2 Copyright (C) 2002-2013 Free Software Foundation, Inc.
3 Contributed by Andy Vaught & Katherine Holcomb
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 3, or (at your option) any later
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING3. If not see
19 <http://www.gnu.org/licenses/>. */
22 /* These functions check to see if an argument list is compatible with
23 a particular intrinsic function or subroutine. Presence of
24 required arguments has already been established, the argument list
25 has been sorted into the right order and has NULL arguments in the
26 correct places for missing optional arguments. */
30 #include "coretypes.h"
33 #include "intrinsic.h"
34 #include "constructor.h"
35 #include "target-memory.h"
38 /* Make sure an expression is a scalar. */
41 scalar_check (gfc_expr
*e
, int n
)
46 gfc_error ("'%s' argument of '%s' intrinsic at %L must be a scalar",
47 gfc_current_intrinsic_arg
[n
]->name
, gfc_current_intrinsic
,
54 /* Check the type of an expression. */
57 type_check (gfc_expr
*e
, int n
, bt type
)
59 if (e
->ts
.type
== type
)
62 gfc_error ("'%s' argument of '%s' intrinsic at %L must be %s",
63 gfc_current_intrinsic_arg
[n
]->name
, gfc_current_intrinsic
,
64 &e
->where
, gfc_basic_typename (type
));
70 /* Check that the expression is a numeric type. */
73 numeric_check (gfc_expr
*e
, int n
)
75 if (gfc_numeric_ts (&e
->ts
))
78 /* If the expression has not got a type, check if its namespace can
79 offer a default type. */
80 if ((e
->expr_type
== EXPR_VARIABLE
|| e
->expr_type
== EXPR_FUNCTION
)
81 && e
->symtree
->n
.sym
->ts
.type
== BT_UNKNOWN
82 && gfc_set_default_type (e
->symtree
->n
.sym
, 0, e
->symtree
->n
.sym
->ns
)
83 && gfc_numeric_ts (&e
->symtree
->n
.sym
->ts
))
85 e
->ts
= e
->symtree
->n
.sym
->ts
;
89 gfc_error ("'%s' argument of '%s' intrinsic at %L must be a numeric type",
90 gfc_current_intrinsic_arg
[n
]->name
, gfc_current_intrinsic
,
97 /* Check that an expression is integer or real. */
100 int_or_real_check (gfc_expr
*e
, int n
)
102 if (e
->ts
.type
!= BT_INTEGER
&& e
->ts
.type
!= BT_REAL
)
104 gfc_error ("'%s' argument of '%s' intrinsic at %L must be INTEGER "
105 "or REAL", gfc_current_intrinsic_arg
[n
]->name
,
106 gfc_current_intrinsic
, &e
->where
);
114 /* Check that an expression is real or complex. */
117 real_or_complex_check (gfc_expr
*e
, int n
)
119 if (e
->ts
.type
!= BT_REAL
&& e
->ts
.type
!= BT_COMPLEX
)
121 gfc_error ("'%s' argument of '%s' intrinsic at %L must be REAL "
122 "or COMPLEX", gfc_current_intrinsic_arg
[n
]->name
,
123 gfc_current_intrinsic
, &e
->where
);
131 /* Check that an expression is INTEGER or PROCEDURE. */
134 int_or_proc_check (gfc_expr
*e
, int n
)
136 if (e
->ts
.type
!= BT_INTEGER
&& e
->ts
.type
!= BT_PROCEDURE
)
138 gfc_error ("'%s' argument of '%s' intrinsic at %L must be INTEGER "
139 "or PROCEDURE", gfc_current_intrinsic_arg
[n
]->name
,
140 gfc_current_intrinsic
, &e
->where
);
148 /* Check that the expression is an optional constant integer
149 and that it specifies a valid kind for that type. */
152 kind_check (gfc_expr
*k
, int n
, bt type
)
159 if (!type_check (k
, n
, BT_INTEGER
))
162 if (!scalar_check (k
, n
))
165 if (!gfc_check_init_expr (k
))
167 gfc_error ("'%s' argument of '%s' intrinsic at %L must be a constant",
168 gfc_current_intrinsic_arg
[n
]->name
, gfc_current_intrinsic
,
173 if (gfc_extract_int (k
, &kind
) != NULL
174 || gfc_validate_kind (type
, kind
, true) < 0)
176 gfc_error ("Invalid kind for %s at %L", gfc_basic_typename (type
),
185 /* Make sure the expression is a double precision real. */
188 double_check (gfc_expr
*d
, int n
)
190 if (!type_check (d
, n
, BT_REAL
))
193 if (d
->ts
.kind
!= gfc_default_double_kind
)
195 gfc_error ("'%s' argument of '%s' intrinsic at %L must be double "
196 "precision", gfc_current_intrinsic_arg
[n
]->name
,
197 gfc_current_intrinsic
, &d
->where
);
206 coarray_check (gfc_expr
*e
, int n
)
208 if (e
->ts
.type
== BT_CLASS
&& gfc_expr_attr (e
).class_ok
209 && CLASS_DATA (e
)->attr
.codimension
210 && CLASS_DATA (e
)->as
->corank
)
212 gfc_add_class_array_ref (e
);
216 if (!gfc_is_coarray (e
))
218 gfc_error ("Expected coarray variable as '%s' argument to the %s "
219 "intrinsic at %L", gfc_current_intrinsic_arg
[n
]->name
,
220 gfc_current_intrinsic
, &e
->where
);
228 /* Make sure the expression is a logical array. */
231 logical_array_check (gfc_expr
*array
, int n
)
233 if (array
->ts
.type
!= BT_LOGICAL
|| array
->rank
== 0)
235 gfc_error ("'%s' argument of '%s' intrinsic at %L must be a logical "
236 "array", gfc_current_intrinsic_arg
[n
]->name
,
237 gfc_current_intrinsic
, &array
->where
);
245 /* Make sure an expression is an array. */
248 array_check (gfc_expr
*e
, int n
)
250 if (e
->ts
.type
== BT_CLASS
&& gfc_expr_attr (e
).class_ok
251 && CLASS_DATA (e
)->attr
.dimension
252 && CLASS_DATA (e
)->as
->rank
)
254 gfc_add_class_array_ref (e
);
258 if (e
->rank
!= 0 && e
->ts
.type
!= BT_PROCEDURE
)
261 gfc_error ("'%s' argument of '%s' intrinsic at %L must be an array",
262 gfc_current_intrinsic_arg
[n
]->name
, gfc_current_intrinsic
,
269 /* If expr is a constant, then check to ensure that it is greater than
273 nonnegative_check (const char *arg
, gfc_expr
*expr
)
277 if (expr
->expr_type
== EXPR_CONSTANT
)
279 gfc_extract_int (expr
, &i
);
282 gfc_error ("'%s' at %L must be nonnegative", arg
, &expr
->where
);
291 /* If expr2 is constant, then check that the value is less than
292 (less than or equal to, if 'or_equal' is true) bit_size(expr1). */
295 less_than_bitsize1 (const char *arg1
, gfc_expr
*expr1
, const char *arg2
,
296 gfc_expr
*expr2
, bool or_equal
)
300 if (expr2
->expr_type
== EXPR_CONSTANT
)
302 gfc_extract_int (expr2
, &i2
);
303 i3
= gfc_validate_kind (BT_INTEGER
, expr1
->ts
.kind
, false);
305 /* For ISHFT[C], check that |shift| <= bit_size(i). */
311 if (i2
> gfc_integer_kinds
[i3
].bit_size
)
313 gfc_error ("The absolute value of SHIFT at %L must be less "
314 "than or equal to BIT_SIZE('%s')",
315 &expr2
->where
, arg1
);
322 if (i2
> gfc_integer_kinds
[i3
].bit_size
)
324 gfc_error ("'%s' at %L must be less than "
325 "or equal to BIT_SIZE('%s')",
326 arg2
, &expr2
->where
, arg1
);
332 if (i2
>= gfc_integer_kinds
[i3
].bit_size
)
334 gfc_error ("'%s' at %L must be less than BIT_SIZE('%s')",
335 arg2
, &expr2
->where
, arg1
);
345 /* If expr is constant, then check that the value is less than or equal
346 to the bit_size of the kind k. */
349 less_than_bitsizekind (const char *arg
, gfc_expr
*expr
, int k
)
353 if (expr
->expr_type
!= EXPR_CONSTANT
)
356 i
= gfc_validate_kind (BT_INTEGER
, k
, false);
357 gfc_extract_int (expr
, &val
);
359 if (val
> gfc_integer_kinds
[i
].bit_size
)
361 gfc_error ("'%s' at %L must be less than or equal to the BIT_SIZE of "
362 "INTEGER(KIND=%d)", arg
, &expr
->where
, k
);
370 /* If expr2 and expr3 are constants, then check that the value is less than
371 or equal to bit_size(expr1). */
374 less_than_bitsize2 (const char *arg1
, gfc_expr
*expr1
, const char *arg2
,
375 gfc_expr
*expr2
, const char *arg3
, gfc_expr
*expr3
)
379 if (expr2
->expr_type
== EXPR_CONSTANT
&& expr3
->expr_type
== EXPR_CONSTANT
)
381 gfc_extract_int (expr2
, &i2
);
382 gfc_extract_int (expr3
, &i3
);
384 i3
= gfc_validate_kind (BT_INTEGER
, expr1
->ts
.kind
, false);
385 if (i2
> gfc_integer_kinds
[i3
].bit_size
)
387 gfc_error ("'%s + %s' at %L must be less than or equal "
389 arg2
, arg3
, &expr2
->where
, arg1
);
397 /* Make sure two expressions have the same type. */
400 same_type_check (gfc_expr
*e
, int n
, gfc_expr
*f
, int m
)
402 if (gfc_compare_types (&e
->ts
, &f
->ts
))
405 gfc_error ("'%s' argument of '%s' intrinsic at %L must be the same type "
406 "and kind as '%s'", gfc_current_intrinsic_arg
[m
]->name
,
407 gfc_current_intrinsic
, &f
->where
,
408 gfc_current_intrinsic_arg
[n
]->name
);
414 /* Make sure that an expression has a certain (nonzero) rank. */
417 rank_check (gfc_expr
*e
, int n
, int rank
)
422 gfc_error ("'%s' argument of '%s' intrinsic at %L must be of rank %d",
423 gfc_current_intrinsic_arg
[n
]->name
, gfc_current_intrinsic
,
430 /* Make sure a variable expression is not an optional dummy argument. */
433 nonoptional_check (gfc_expr
*e
, int n
)
435 if (e
->expr_type
== EXPR_VARIABLE
&& e
->symtree
->n
.sym
->attr
.optional
)
437 gfc_error ("'%s' argument of '%s' intrinsic at %L must not be OPTIONAL",
438 gfc_current_intrinsic_arg
[n
]->name
, gfc_current_intrinsic
,
442 /* TODO: Recursive check on nonoptional variables? */
448 /* Check for ALLOCATABLE attribute. */
451 allocatable_check (gfc_expr
*e
, int n
)
453 symbol_attribute attr
;
455 attr
= gfc_variable_attr (e
, NULL
);
456 if (!attr
.allocatable
|| attr
.associate_var
)
458 gfc_error ("'%s' argument of '%s' intrinsic at %L must be ALLOCATABLE",
459 gfc_current_intrinsic_arg
[n
]->name
, gfc_current_intrinsic
,
468 /* Check that an expression has a particular kind. */
471 kind_value_check (gfc_expr
*e
, int n
, int k
)
476 gfc_error ("'%s' argument of '%s' intrinsic at %L must be of kind %d",
477 gfc_current_intrinsic_arg
[n
]->name
, gfc_current_intrinsic
,
484 /* Make sure an expression is a variable. */
487 variable_check (gfc_expr
*e
, int n
, bool allow_proc
)
489 if (e
->expr_type
== EXPR_VARIABLE
490 && e
->symtree
->n
.sym
->attr
.intent
== INTENT_IN
491 && (gfc_current_intrinsic_arg
[n
]->intent
== INTENT_OUT
492 || gfc_current_intrinsic_arg
[n
]->intent
== INTENT_INOUT
))
495 bool pointer
= e
->symtree
->n
.sym
->ts
.type
== BT_CLASS
496 && CLASS_DATA (e
->symtree
->n
.sym
)
497 ? CLASS_DATA (e
->symtree
->n
.sym
)->attr
.class_pointer
498 : e
->symtree
->n
.sym
->attr
.pointer
;
500 for (ref
= e
->ref
; ref
; ref
= ref
->next
)
502 if (pointer
&& ref
->type
== REF_COMPONENT
)
504 if (ref
->type
== REF_COMPONENT
505 && ((ref
->u
.c
.component
->ts
.type
== BT_CLASS
506 && CLASS_DATA (ref
->u
.c
.component
)->attr
.class_pointer
)
507 || (ref
->u
.c
.component
->ts
.type
!= BT_CLASS
508 && ref
->u
.c
.component
->attr
.pointer
)))
514 gfc_error ("'%s' argument of '%s' intrinsic at %L cannot be "
515 "INTENT(IN)", gfc_current_intrinsic_arg
[n
]->name
,
516 gfc_current_intrinsic
, &e
->where
);
521 if (e
->expr_type
== EXPR_VARIABLE
522 && e
->symtree
->n
.sym
->attr
.flavor
!= FL_PARAMETER
523 && (allow_proc
|| !e
->symtree
->n
.sym
->attr
.function
))
526 if (e
->expr_type
== EXPR_VARIABLE
&& e
->symtree
->n
.sym
->attr
.function
527 && e
->symtree
->n
.sym
== e
->symtree
->n
.sym
->result
)
530 for (ns
= gfc_current_ns
; ns
; ns
= ns
->parent
)
531 if (ns
->proc_name
== e
->symtree
->n
.sym
)
535 gfc_error ("'%s' argument of '%s' intrinsic at %L must be a variable",
536 gfc_current_intrinsic_arg
[n
]->name
, gfc_current_intrinsic
, &e
->where
);
542 /* Check the common DIM parameter for correctness. */
545 dim_check (gfc_expr
*dim
, int n
, bool optional
)
550 if (!type_check (dim
, n
, BT_INTEGER
))
553 if (!scalar_check (dim
, n
))
556 if (!optional
&& !nonoptional_check (dim
, n
))
563 /* If a coarray DIM parameter is a constant, make sure that it is greater than
564 zero and less than or equal to the corank of the given array. */
567 dim_corank_check (gfc_expr
*dim
, gfc_expr
*array
)
571 gcc_assert (array
->expr_type
== EXPR_VARIABLE
);
573 if (dim
->expr_type
!= EXPR_CONSTANT
)
576 if (array
->ts
.type
== BT_CLASS
)
579 corank
= gfc_get_corank (array
);
581 if (mpz_cmp_ui (dim
->value
.integer
, 1) < 0
582 || mpz_cmp_ui (dim
->value
.integer
, corank
) > 0)
584 gfc_error ("'dim' argument of '%s' intrinsic at %L is not a valid "
585 "codimension index", gfc_current_intrinsic
, &dim
->where
);
594 /* If a DIM parameter is a constant, make sure that it is greater than
595 zero and less than or equal to the rank of the given array. If
596 allow_assumed is zero then dim must be less than the rank of the array
597 for assumed size arrays. */
600 dim_rank_check (gfc_expr
*dim
, gfc_expr
*array
, int allow_assumed
)
608 if (dim
->expr_type
!= EXPR_CONSTANT
)
611 if (array
->ts
.type
== BT_CLASS
)
614 if (array
->expr_type
== EXPR_FUNCTION
&& array
->value
.function
.isym
615 && array
->value
.function
.isym
->id
== GFC_ISYM_SPREAD
)
616 rank
= array
->rank
+ 1;
620 /* Assumed-rank array. */
622 rank
= GFC_MAX_DIMENSIONS
;
624 if (array
->expr_type
== EXPR_VARIABLE
)
626 ar
= gfc_find_array_ref (array
);
627 if (ar
->as
->type
== AS_ASSUMED_SIZE
629 && ar
->type
!= AR_ELEMENT
630 && ar
->type
!= AR_SECTION
)
634 if (mpz_cmp_ui (dim
->value
.integer
, 1) < 0
635 || mpz_cmp_ui (dim
->value
.integer
, rank
) > 0)
637 gfc_error ("'dim' argument of '%s' intrinsic at %L is not a valid "
638 "dimension index", gfc_current_intrinsic
, &dim
->where
);
647 /* Compare the size of a along dimension ai with the size of b along
648 dimension bi, returning 0 if they are known not to be identical,
649 and 1 if they are identical, or if this cannot be determined. */
652 identical_dimen_shape (gfc_expr
*a
, int ai
, gfc_expr
*b
, int bi
)
654 mpz_t a_size
, b_size
;
657 gcc_assert (a
->rank
> ai
);
658 gcc_assert (b
->rank
> bi
);
662 if (gfc_array_dimen_size (a
, ai
, &a_size
))
664 if (gfc_array_dimen_size (b
, bi
, &b_size
))
666 if (mpz_cmp (a_size
, b_size
) != 0)
676 /* Calculate the length of a character variable, including substrings.
677 Strip away parentheses if necessary. Return -1 if no length could
681 gfc_var_strlen (const gfc_expr
*a
)
685 while (a
->expr_type
== EXPR_OP
&& a
->value
.op
.op
== INTRINSIC_PARENTHESES
)
688 for (ra
= a
->ref
; ra
!= NULL
&& ra
->type
!= REF_SUBSTRING
; ra
= ra
->next
)
698 if ((!ra
->u
.ss
.start
|| ra
->u
.ss
.start
->expr_type
== EXPR_CONSTANT
)
699 && ra
->u
.ss
.end
->expr_type
== EXPR_CONSTANT
)
701 start_a
= ra
->u
.ss
.start
? mpz_get_si (ra
->u
.ss
.start
->value
.integer
)
703 end_a
= mpz_get_si (ra
->u
.ss
.end
->value
.integer
);
704 return (end_a
< start_a
) ? 0 : end_a
- start_a
+ 1;
706 else if (ra
->u
.ss
.start
707 && gfc_dep_compare_expr (ra
->u
.ss
.start
, ra
->u
.ss
.end
) == 0)
713 if (a
->ts
.u
.cl
&& a
->ts
.u
.cl
->length
714 && a
->ts
.u
.cl
->length
->expr_type
== EXPR_CONSTANT
)
715 return mpz_get_si (a
->ts
.u
.cl
->length
->value
.integer
);
716 else if (a
->expr_type
== EXPR_CONSTANT
717 && (a
->ts
.u
.cl
== NULL
|| a
->ts
.u
.cl
->length
== NULL
))
718 return a
->value
.character
.length
;
724 /* Check whether two character expressions have the same length;
725 returns true if they have or if the length cannot be determined,
726 otherwise return false and raise a gfc_error. */
729 gfc_check_same_strlen (const gfc_expr
*a
, const gfc_expr
*b
, const char *name
)
733 len_a
= gfc_var_strlen(a
);
734 len_b
= gfc_var_strlen(b
);
736 if (len_a
== -1 || len_b
== -1 || len_a
== len_b
)
740 gfc_error ("Unequal character lengths (%ld/%ld) in %s at %L",
741 len_a
, len_b
, name
, &a
->where
);
747 /***** Check functions *****/
749 /* Check subroutine suitable for intrinsics taking a real argument and
750 a kind argument for the result. */
753 check_a_kind (gfc_expr
*a
, gfc_expr
*kind
, bt type
)
755 if (!type_check (a
, 0, BT_REAL
))
757 if (!kind_check (kind
, 1, type
))
764 /* Check subroutine suitable for ceiling, floor and nint. */
767 gfc_check_a_ikind (gfc_expr
*a
, gfc_expr
*kind
)
769 return check_a_kind (a
, kind
, BT_INTEGER
);
773 /* Check subroutine suitable for aint, anint. */
776 gfc_check_a_xkind (gfc_expr
*a
, gfc_expr
*kind
)
778 return check_a_kind (a
, kind
, BT_REAL
);
783 gfc_check_abs (gfc_expr
*a
)
785 if (!numeric_check (a
, 0))
793 gfc_check_achar (gfc_expr
*a
, gfc_expr
*kind
)
795 if (!type_check (a
, 0, BT_INTEGER
))
797 if (!kind_check (kind
, 1, BT_CHARACTER
))
805 gfc_check_access_func (gfc_expr
*name
, gfc_expr
*mode
)
807 if (!type_check (name
, 0, BT_CHARACTER
)
808 || !scalar_check (name
, 0))
810 if (!kind_value_check (name
, 0, gfc_default_character_kind
))
813 if (!type_check (mode
, 1, BT_CHARACTER
)
814 || !scalar_check (mode
, 1))
816 if (!kind_value_check (mode
, 1, gfc_default_character_kind
))
824 gfc_check_all_any (gfc_expr
*mask
, gfc_expr
*dim
)
826 if (!logical_array_check (mask
, 0))
829 if (!dim_check (dim
, 1, false))
832 if (!dim_rank_check (dim
, mask
, 0))
840 gfc_check_allocated (gfc_expr
*array
)
842 if (!variable_check (array
, 0, false))
844 if (!allocatable_check (array
, 0))
851 /* Common check function where the first argument must be real or
852 integer and the second argument must be the same as the first. */
855 gfc_check_a_p (gfc_expr
*a
, gfc_expr
*p
)
857 if (!int_or_real_check (a
, 0))
860 if (a
->ts
.type
!= p
->ts
.type
)
862 gfc_error ("'%s' and '%s' arguments of '%s' intrinsic at %L must "
863 "have the same type", gfc_current_intrinsic_arg
[0]->name
,
864 gfc_current_intrinsic_arg
[1]->name
, gfc_current_intrinsic
,
869 if (a
->ts
.kind
!= p
->ts
.kind
)
871 if (!gfc_notify_std (GFC_STD_GNU
, "Different type kinds at %L",
881 gfc_check_x_yd (gfc_expr
*x
, gfc_expr
*y
)
883 if (!double_check (x
, 0) || !double_check (y
, 1))
891 gfc_check_associated (gfc_expr
*pointer
, gfc_expr
*target
)
893 symbol_attribute attr1
, attr2
;
898 where
= &pointer
->where
;
900 if (pointer
->expr_type
== EXPR_NULL
)
903 attr1
= gfc_expr_attr (pointer
);
905 if (!attr1
.pointer
&& !attr1
.proc_pointer
)
907 gfc_error ("'%s' argument of '%s' intrinsic at %L must be a POINTER",
908 gfc_current_intrinsic_arg
[0]->name
, gfc_current_intrinsic
,
914 if (attr1
.pointer
&& gfc_is_coindexed (pointer
))
916 gfc_error ("'%s' argument of '%s' intrinsic at %L shall not be "
917 "coindexed", gfc_current_intrinsic_arg
[0]->name
,
918 gfc_current_intrinsic
, &pointer
->where
);
922 /* Target argument is optional. */
926 where
= &target
->where
;
927 if (target
->expr_type
== EXPR_NULL
)
930 if (target
->expr_type
== EXPR_VARIABLE
|| target
->expr_type
== EXPR_FUNCTION
)
931 attr2
= gfc_expr_attr (target
);
934 gfc_error ("'%s' argument of '%s' intrinsic at %L must be a pointer "
935 "or target VARIABLE or FUNCTION",
936 gfc_current_intrinsic_arg
[1]->name
, gfc_current_intrinsic
,
941 if (attr1
.pointer
&& !attr2
.pointer
&& !attr2
.target
)
943 gfc_error ("'%s' argument of '%s' intrinsic at %L must be a POINTER "
944 "or a TARGET", gfc_current_intrinsic_arg
[1]->name
,
945 gfc_current_intrinsic
, &target
->where
);
950 if (attr1
.pointer
&& gfc_is_coindexed (target
))
952 gfc_error ("'%s' argument of '%s' intrinsic at %L shall not be "
953 "coindexed", gfc_current_intrinsic_arg
[1]->name
,
954 gfc_current_intrinsic
, &target
->where
);
959 if (!same_type_check (pointer
, 0, target
, 1))
961 if (!rank_check (target
, 0, pointer
->rank
))
963 if (target
->rank
> 0)
965 for (i
= 0; i
< target
->rank
; i
++)
966 if (target
->ref
->u
.ar
.dimen_type
[i
] == DIMEN_VECTOR
)
968 gfc_error ("Array section with a vector subscript at %L shall not "
969 "be the target of a pointer",
979 gfc_error ("NULL pointer at %L is not permitted as actual argument "
980 "of '%s' intrinsic function", where
, gfc_current_intrinsic
);
987 gfc_check_atan_2 (gfc_expr
*y
, gfc_expr
*x
)
989 /* gfc_notify_std would be a waste of time as the return value
990 is seemingly used only for the generic resolution. The error
991 will be: Too many arguments. */
992 if ((gfc_option
.allow_std
& GFC_STD_F2008
) == 0)
995 return gfc_check_atan2 (y
, x
);
1000 gfc_check_atan2 (gfc_expr
*y
, gfc_expr
*x
)
1002 if (!type_check (y
, 0, BT_REAL
))
1004 if (!same_type_check (y
, 0, x
, 1))
1012 gfc_check_atomic (gfc_expr
*atom
, gfc_expr
*value
)
1014 if (!(atom
->ts
.type
== BT_INTEGER
&& atom
->ts
.kind
== gfc_atomic_int_kind
)
1015 && !(atom
->ts
.type
== BT_LOGICAL
1016 && atom
->ts
.kind
== gfc_atomic_logical_kind
))
1018 gfc_error ("ATOM argument at %L to intrinsic function %s shall be an "
1019 "integer of ATOMIC_INT_KIND or a logical of "
1020 "ATOMIC_LOGICAL_KIND", &atom
->where
, gfc_current_intrinsic
);
1024 if (!gfc_expr_attr (atom
).codimension
)
1026 gfc_error ("ATOM argument at %L of the %s intrinsic function shall be a "
1027 "coarray or coindexed", &atom
->where
, gfc_current_intrinsic
);
1031 if (atom
->ts
.type
!= value
->ts
.type
)
1033 gfc_error ("ATOM and VALUE argument of the %s intrinsic function shall "
1034 "have the same type at %L", gfc_current_intrinsic
,
1044 gfc_check_atomic_def (gfc_expr
*atom
, gfc_expr
*value
)
1046 if (!scalar_check (atom
, 0) || !scalar_check (value
, 1))
1049 if (!gfc_check_vardef_context (atom
, false, false, false, NULL
))
1051 gfc_error ("ATOM argument of the %s intrinsic function at %L shall be "
1052 "definable", gfc_current_intrinsic
, &atom
->where
);
1056 return gfc_check_atomic (atom
, value
);
1061 gfc_check_atomic_ref (gfc_expr
*value
, gfc_expr
*atom
)
1063 if (!scalar_check (value
, 0) || !scalar_check (atom
, 1))
1066 if (!gfc_check_vardef_context (value
, false, false, false, NULL
))
1068 gfc_error ("VALUE argument of the %s intrinsic function at %L shall be "
1069 "definable", gfc_current_intrinsic
, &value
->where
);
1073 return gfc_check_atomic (atom
, value
);
1077 /* BESJN and BESYN functions. */
1080 gfc_check_besn (gfc_expr
*n
, gfc_expr
*x
)
1082 if (!type_check (n
, 0, BT_INTEGER
))
1084 if (n
->expr_type
== EXPR_CONSTANT
)
1087 gfc_extract_int (n
, &i
);
1088 if (i
< 0 && !gfc_notify_std (GFC_STD_GNU
, "Negative argument "
1089 "N at %L", &n
->where
))
1093 if (!type_check (x
, 1, BT_REAL
))
1100 /* Transformational version of the Bessel JN and YN functions. */
1103 gfc_check_bessel_n2 (gfc_expr
*n1
, gfc_expr
*n2
, gfc_expr
*x
)
1105 if (!type_check (n1
, 0, BT_INTEGER
))
1107 if (!scalar_check (n1
, 0))
1109 if (!nonnegative_check ("N1", n1
))
1112 if (!type_check (n2
, 1, BT_INTEGER
))
1114 if (!scalar_check (n2
, 1))
1116 if (!nonnegative_check ("N2", n2
))
1119 if (!type_check (x
, 2, BT_REAL
))
1121 if (!scalar_check (x
, 2))
1129 gfc_check_bge_bgt_ble_blt (gfc_expr
*i
, gfc_expr
*j
)
1131 if (!type_check (i
, 0, BT_INTEGER
))
1134 if (!type_check (j
, 1, BT_INTEGER
))
1142 gfc_check_bitfcn (gfc_expr
*i
, gfc_expr
*pos
)
1144 if (!type_check (i
, 0, BT_INTEGER
))
1147 if (!type_check (pos
, 1, BT_INTEGER
))
1150 if (!nonnegative_check ("pos", pos
))
1153 if (!less_than_bitsize1 ("i", i
, "pos", pos
, false))
1161 gfc_check_char (gfc_expr
*i
, gfc_expr
*kind
)
1163 if (!type_check (i
, 0, BT_INTEGER
))
1165 if (!kind_check (kind
, 1, BT_CHARACTER
))
1173 gfc_check_chdir (gfc_expr
*dir
)
1175 if (!type_check (dir
, 0, BT_CHARACTER
))
1177 if (!kind_value_check (dir
, 0, gfc_default_character_kind
))
1185 gfc_check_chdir_sub (gfc_expr
*dir
, gfc_expr
*status
)
1187 if (!type_check (dir
, 0, BT_CHARACTER
))
1189 if (!kind_value_check (dir
, 0, gfc_default_character_kind
))
1195 if (!type_check (status
, 1, BT_INTEGER
))
1197 if (!scalar_check (status
, 1))
1205 gfc_check_chmod (gfc_expr
*name
, gfc_expr
*mode
)
1207 if (!type_check (name
, 0, BT_CHARACTER
))
1209 if (!kind_value_check (name
, 0, gfc_default_character_kind
))
1212 if (!type_check (mode
, 1, BT_CHARACTER
))
1214 if (!kind_value_check (mode
, 1, gfc_default_character_kind
))
1222 gfc_check_chmod_sub (gfc_expr
*name
, gfc_expr
*mode
, gfc_expr
*status
)
1224 if (!type_check (name
, 0, BT_CHARACTER
))
1226 if (!kind_value_check (name
, 0, gfc_default_character_kind
))
1229 if (!type_check (mode
, 1, BT_CHARACTER
))
1231 if (!kind_value_check (mode
, 1, gfc_default_character_kind
))
1237 if (!type_check (status
, 2, BT_INTEGER
))
1240 if (!scalar_check (status
, 2))
1248 gfc_check_cmplx (gfc_expr
*x
, gfc_expr
*y
, gfc_expr
*kind
)
1250 if (!numeric_check (x
, 0))
1255 if (!numeric_check (y
, 1))
1258 if (x
->ts
.type
== BT_COMPLEX
)
1260 gfc_error ("'%s' argument of '%s' intrinsic at %L must not be "
1261 "present if 'x' is COMPLEX",
1262 gfc_current_intrinsic_arg
[1]->name
, gfc_current_intrinsic
,
1267 if (y
->ts
.type
== BT_COMPLEX
)
1269 gfc_error ("'%s' argument of '%s' intrinsic at %L must have a type "
1270 "of either REAL or INTEGER",
1271 gfc_current_intrinsic_arg
[1]->name
, gfc_current_intrinsic
,
1278 if (!kind_check (kind
, 2, BT_COMPLEX
))
1281 if (!kind
&& gfc_option
.gfc_warn_conversion
1282 && x
->ts
.type
== BT_REAL
&& x
->ts
.kind
> gfc_default_real_kind
)
1283 gfc_warning_now ("Conversion from %s to default-kind COMPLEX(%d) at %L "
1284 "might loose precision, consider using the KIND argument",
1285 gfc_typename (&x
->ts
), gfc_default_real_kind
, &x
->where
);
1286 else if (y
&& !kind
&& gfc_option
.gfc_warn_conversion
1287 && y
->ts
.type
== BT_REAL
&& y
->ts
.kind
> gfc_default_real_kind
)
1288 gfc_warning_now ("Conversion from %s to default-kind COMPLEX(%d) at %L "
1289 "might loose precision, consider using the KIND argument",
1290 gfc_typename (&y
->ts
), gfc_default_real_kind
, &y
->where
);
1297 gfc_check_complex (gfc_expr
*x
, gfc_expr
*y
)
1299 if (!int_or_real_check (x
, 0))
1301 if (!scalar_check (x
, 0))
1304 if (!int_or_real_check (y
, 1))
1306 if (!scalar_check (y
, 1))
1314 gfc_check_count (gfc_expr
*mask
, gfc_expr
*dim
, gfc_expr
*kind
)
1316 if (!logical_array_check (mask
, 0))
1318 if (!dim_check (dim
, 1, false))
1320 if (!dim_rank_check (dim
, mask
, 0))
1322 if (!kind_check (kind
, 2, BT_INTEGER
))
1324 if (kind
&& !gfc_notify_std (GFC_STD_F2003
, "'%s' intrinsic "
1325 "with KIND argument at %L",
1326 gfc_current_intrinsic
, &kind
->where
))
1334 gfc_check_cshift (gfc_expr
*array
, gfc_expr
*shift
, gfc_expr
*dim
)
1336 if (!array_check (array
, 0))
1339 if (!type_check (shift
, 1, BT_INTEGER
))
1342 if (!dim_check (dim
, 2, true))
1345 if (!dim_rank_check (dim
, array
, false))
1348 if (array
->rank
== 1 || shift
->rank
== 0)
1350 if (!scalar_check (shift
, 1))
1353 else if (shift
->rank
== array
->rank
- 1)
1358 else if (dim
->expr_type
== EXPR_CONSTANT
)
1359 gfc_extract_int (dim
, &d
);
1366 for (i
= 0, j
= 0; i
< array
->rank
; i
++)
1369 if (!identical_dimen_shape (array
, i
, shift
, j
))
1371 gfc_error ("'%s' argument of '%s' intrinsic at %L has "
1372 "invalid shape in dimension %d (%ld/%ld)",
1373 gfc_current_intrinsic_arg
[1]->name
,
1374 gfc_current_intrinsic
, &shift
->where
, i
+ 1,
1375 mpz_get_si (array
->shape
[i
]),
1376 mpz_get_si (shift
->shape
[j
]));
1386 gfc_error ("'%s' argument of intrinsic '%s' at %L of must have rank "
1387 "%d or be a scalar", gfc_current_intrinsic_arg
[1]->name
,
1388 gfc_current_intrinsic
, &shift
->where
, array
->rank
- 1);
1397 gfc_check_ctime (gfc_expr
*time
)
1399 if (!scalar_check (time
, 0))
1402 if (!type_check (time
, 0, BT_INTEGER
))
1409 bool gfc_check_datan2 (gfc_expr
*y
, gfc_expr
*x
)
1411 if (!double_check (y
, 0) || !double_check (x
, 1))
1418 gfc_check_dcmplx (gfc_expr
*x
, gfc_expr
*y
)
1420 if (!numeric_check (x
, 0))
1425 if (!numeric_check (y
, 1))
1428 if (x
->ts
.type
== BT_COMPLEX
)
1430 gfc_error ("'%s' argument of '%s' intrinsic at %L must not be "
1431 "present if 'x' is COMPLEX",
1432 gfc_current_intrinsic_arg
[1]->name
, gfc_current_intrinsic
,
1437 if (y
->ts
.type
== BT_COMPLEX
)
1439 gfc_error ("'%s' argument of '%s' intrinsic at %L must have a type "
1440 "of either REAL or INTEGER",
1441 gfc_current_intrinsic_arg
[1]->name
, gfc_current_intrinsic
,
1452 gfc_check_dble (gfc_expr
*x
)
1454 if (!numeric_check (x
, 0))
1462 gfc_check_digits (gfc_expr
*x
)
1464 if (!int_or_real_check (x
, 0))
1472 gfc_check_dot_product (gfc_expr
*vector_a
, gfc_expr
*vector_b
)
1474 switch (vector_a
->ts
.type
)
1477 if (!type_check (vector_b
, 1, BT_LOGICAL
))
1484 if (!numeric_check (vector_b
, 1))
1489 gfc_error ("'%s' argument of '%s' intrinsic at %L must be numeric "
1490 "or LOGICAL", gfc_current_intrinsic_arg
[0]->name
,
1491 gfc_current_intrinsic
, &vector_a
->where
);
1495 if (!rank_check (vector_a
, 0, 1))
1498 if (!rank_check (vector_b
, 1, 1))
1501 if (! identical_dimen_shape (vector_a
, 0, vector_b
, 0))
1503 gfc_error ("Different shape for arguments '%s' and '%s' at %L for "
1504 "intrinsic 'dot_product'", gfc_current_intrinsic_arg
[0]->name
,
1505 gfc_current_intrinsic_arg
[1]->name
, &vector_a
->where
);
1514 gfc_check_dprod (gfc_expr
*x
, gfc_expr
*y
)
1516 if (!type_check (x
, 0, BT_REAL
)
1517 || !type_check (y
, 1, BT_REAL
))
1520 if (x
->ts
.kind
!= gfc_default_real_kind
)
1522 gfc_error ("'%s' argument of '%s' intrinsic at %L must be default "
1523 "real", gfc_current_intrinsic_arg
[0]->name
,
1524 gfc_current_intrinsic
, &x
->where
);
1528 if (y
->ts
.kind
!= gfc_default_real_kind
)
1530 gfc_error ("'%s' argument of '%s' intrinsic at %L must be default "
1531 "real", gfc_current_intrinsic_arg
[1]->name
,
1532 gfc_current_intrinsic
, &y
->where
);
1541 gfc_check_dshift (gfc_expr
*i
, gfc_expr
*j
, gfc_expr
*shift
)
1543 if (!type_check (i
, 0, BT_INTEGER
))
1546 if (!type_check (j
, 1, BT_INTEGER
))
1549 if (i
->is_boz
&& j
->is_boz
)
1551 gfc_error ("'I' at %L and 'J' at %L cannot both be BOZ literal "
1552 "constants", &i
->where
, &j
->where
);
1556 if (!i
->is_boz
&& !j
->is_boz
&& !same_type_check (i
, 0, j
, 1))
1559 if (!type_check (shift
, 2, BT_INTEGER
))
1562 if (!nonnegative_check ("SHIFT", shift
))
1567 if (!less_than_bitsize1 ("J", j
, "SHIFT", shift
, true))
1569 i
->ts
.kind
= j
->ts
.kind
;
1573 if (!less_than_bitsize1 ("I", i
, "SHIFT", shift
, true))
1575 j
->ts
.kind
= i
->ts
.kind
;
1583 gfc_check_eoshift (gfc_expr
*array
, gfc_expr
*shift
, gfc_expr
*boundary
,
1586 if (!array_check (array
, 0))
1589 if (!type_check (shift
, 1, BT_INTEGER
))
1592 if (!dim_check (dim
, 3, true))
1595 if (!dim_rank_check (dim
, array
, false))
1598 if (array
->rank
== 1 || shift
->rank
== 0)
1600 if (!scalar_check (shift
, 1))
1603 else if (shift
->rank
== array
->rank
- 1)
1608 else if (dim
->expr_type
== EXPR_CONSTANT
)
1609 gfc_extract_int (dim
, &d
);
1616 for (i
= 0, j
= 0; i
< array
->rank
; i
++)
1619 if (!identical_dimen_shape (array
, i
, shift
, j
))
1621 gfc_error ("'%s' argument of '%s' intrinsic at %L has "
1622 "invalid shape in dimension %d (%ld/%ld)",
1623 gfc_current_intrinsic_arg
[1]->name
,
1624 gfc_current_intrinsic
, &shift
->where
, i
+ 1,
1625 mpz_get_si (array
->shape
[i
]),
1626 mpz_get_si (shift
->shape
[j
]));
1636 gfc_error ("'%s' argument of intrinsic '%s' at %L of must have rank "
1637 "%d or be a scalar", gfc_current_intrinsic_arg
[1]->name
,
1638 gfc_current_intrinsic
, &shift
->where
, array
->rank
- 1);
1642 if (boundary
!= NULL
)
1644 if (!same_type_check (array
, 0, boundary
, 2))
1647 if (array
->rank
== 1 || boundary
->rank
== 0)
1649 if (!scalar_check (boundary
, 2))
1652 else if (boundary
->rank
== array
->rank
- 1)
1654 if (!gfc_check_conformance (shift
, boundary
,
1655 "arguments '%s' and '%s' for "
1657 gfc_current_intrinsic_arg
[1]->name
,
1658 gfc_current_intrinsic_arg
[2]->name
,
1659 gfc_current_intrinsic
))
1664 gfc_error ("'%s' argument of intrinsic '%s' at %L of must have "
1665 "rank %d or be a scalar",
1666 gfc_current_intrinsic_arg
[1]->name
, gfc_current_intrinsic
,
1667 &shift
->where
, array
->rank
- 1);
1676 gfc_check_float (gfc_expr
*a
)
1678 if (!type_check (a
, 0, BT_INTEGER
))
1681 if ((a
->ts
.kind
!= gfc_default_integer_kind
)
1682 && !gfc_notify_std (GFC_STD_GNU
, "non-default INTEGER "
1683 "kind argument to %s intrinsic at %L",
1684 gfc_current_intrinsic
, &a
->where
))
1690 /* A single complex argument. */
1693 gfc_check_fn_c (gfc_expr
*a
)
1695 if (!type_check (a
, 0, BT_COMPLEX
))
1701 /* A single real argument. */
1704 gfc_check_fn_r (gfc_expr
*a
)
1706 if (!type_check (a
, 0, BT_REAL
))
1712 /* A single double argument. */
1715 gfc_check_fn_d (gfc_expr
*a
)
1717 if (!double_check (a
, 0))
1723 /* A single real or complex argument. */
1726 gfc_check_fn_rc (gfc_expr
*a
)
1728 if (!real_or_complex_check (a
, 0))
1736 gfc_check_fn_rc2008 (gfc_expr
*a
)
1738 if (!real_or_complex_check (a
, 0))
1741 if (a
->ts
.type
== BT_COMPLEX
1742 && !gfc_notify_std (GFC_STD_F2008
, "COMPLEX argument '%s' "
1743 "argument of '%s' intrinsic at %L",
1744 gfc_current_intrinsic_arg
[0]->name
,
1745 gfc_current_intrinsic
, &a
->where
))
1753 gfc_check_fnum (gfc_expr
*unit
)
1755 if (!type_check (unit
, 0, BT_INTEGER
))
1758 if (!scalar_check (unit
, 0))
1766 gfc_check_huge (gfc_expr
*x
)
1768 if (!int_or_real_check (x
, 0))
1776 gfc_check_hypot (gfc_expr
*x
, gfc_expr
*y
)
1778 if (!type_check (x
, 0, BT_REAL
))
1780 if (!same_type_check (x
, 0, y
, 1))
1787 /* Check that the single argument is an integer. */
1790 gfc_check_i (gfc_expr
*i
)
1792 if (!type_check (i
, 0, BT_INTEGER
))
1800 gfc_check_iand (gfc_expr
*i
, gfc_expr
*j
)
1802 if (!type_check (i
, 0, BT_INTEGER
))
1805 if (!type_check (j
, 1, BT_INTEGER
))
1808 if (i
->ts
.kind
!= j
->ts
.kind
)
1810 if (!gfc_notify_std (GFC_STD_GNU
, "Different type kinds at %L",
1820 gfc_check_ibits (gfc_expr
*i
, gfc_expr
*pos
, gfc_expr
*len
)
1822 if (!type_check (i
, 0, BT_INTEGER
))
1825 if (!type_check (pos
, 1, BT_INTEGER
))
1828 if (!type_check (len
, 2, BT_INTEGER
))
1831 if (!nonnegative_check ("pos", pos
))
1834 if (!nonnegative_check ("len", len
))
1837 if (!less_than_bitsize2 ("i", i
, "pos", pos
, "len", len
))
1845 gfc_check_ichar_iachar (gfc_expr
*c
, gfc_expr
*kind
)
1849 if (!type_check (c
, 0, BT_CHARACTER
))
1852 if (!kind_check (kind
, 1, BT_INTEGER
))
1855 if (kind
&& !gfc_notify_std (GFC_STD_F2003
, "'%s' intrinsic "
1856 "with KIND argument at %L",
1857 gfc_current_intrinsic
, &kind
->where
))
1860 if (c
->expr_type
== EXPR_VARIABLE
|| c
->expr_type
== EXPR_SUBSTRING
)
1866 /* Substring references don't have the charlength set. */
1868 while (ref
&& ref
->type
!= REF_SUBSTRING
)
1871 gcc_assert (ref
== NULL
|| ref
->type
== REF_SUBSTRING
);
1875 /* Check that the argument is length one. Non-constant lengths
1876 can't be checked here, so assume they are ok. */
1877 if (c
->ts
.u
.cl
&& c
->ts
.u
.cl
->length
)
1879 /* If we already have a length for this expression then use it. */
1880 if (c
->ts
.u
.cl
->length
->expr_type
!= EXPR_CONSTANT
)
1882 i
= mpz_get_si (c
->ts
.u
.cl
->length
->value
.integer
);
1889 start
= ref
->u
.ss
.start
;
1890 end
= ref
->u
.ss
.end
;
1893 if (end
== NULL
|| end
->expr_type
!= EXPR_CONSTANT
1894 || start
->expr_type
!= EXPR_CONSTANT
)
1897 i
= mpz_get_si (end
->value
.integer
) + 1
1898 - mpz_get_si (start
->value
.integer
);
1906 gfc_error ("Argument of %s at %L must be of length one",
1907 gfc_current_intrinsic
, &c
->where
);
1916 gfc_check_idnint (gfc_expr
*a
)
1918 if (!double_check (a
, 0))
1926 gfc_check_ieor (gfc_expr
*i
, gfc_expr
*j
)
1928 if (!type_check (i
, 0, BT_INTEGER
))
1931 if (!type_check (j
, 1, BT_INTEGER
))
1934 if (i
->ts
.kind
!= j
->ts
.kind
)
1936 if (!gfc_notify_std (GFC_STD_GNU
, "Different type kinds at %L",
1946 gfc_check_index (gfc_expr
*string
, gfc_expr
*substring
, gfc_expr
*back
,
1949 if (!type_check (string
, 0, BT_CHARACTER
)
1950 || !type_check (substring
, 1, BT_CHARACTER
))
1953 if (back
!= NULL
&& !type_check (back
, 2, BT_LOGICAL
))
1956 if (!kind_check (kind
, 3, BT_INTEGER
))
1958 if (kind
&& !gfc_notify_std (GFC_STD_F2003
, "'%s' intrinsic "
1959 "with KIND argument at %L",
1960 gfc_current_intrinsic
, &kind
->where
))
1963 if (string
->ts
.kind
!= substring
->ts
.kind
)
1965 gfc_error ("'%s' argument of '%s' intrinsic at %L must be the same "
1966 "kind as '%s'", gfc_current_intrinsic_arg
[1]->name
,
1967 gfc_current_intrinsic
, &substring
->where
,
1968 gfc_current_intrinsic_arg
[0]->name
);
1977 gfc_check_int (gfc_expr
*x
, gfc_expr
*kind
)
1979 if (!numeric_check (x
, 0))
1982 if (!kind_check (kind
, 1, BT_INTEGER
))
1990 gfc_check_intconv (gfc_expr
*x
)
1992 if (!numeric_check (x
, 0))
2000 gfc_check_ior (gfc_expr
*i
, gfc_expr
*j
)
2002 if (!type_check (i
, 0, BT_INTEGER
))
2005 if (!type_check (j
, 1, BT_INTEGER
))
2008 if (i
->ts
.kind
!= j
->ts
.kind
)
2010 if (!gfc_notify_std (GFC_STD_GNU
, "Different type kinds at %L",
2020 gfc_check_ishft (gfc_expr
*i
, gfc_expr
*shift
)
2022 if (!type_check (i
, 0, BT_INTEGER
)
2023 || !type_check (shift
, 1, BT_INTEGER
))
2026 if (!less_than_bitsize1 ("I", i
, NULL
, shift
, true))
2034 gfc_check_ishftc (gfc_expr
*i
, gfc_expr
*shift
, gfc_expr
*size
)
2036 if (!type_check (i
, 0, BT_INTEGER
)
2037 || !type_check (shift
, 1, BT_INTEGER
))
2044 if (!type_check (size
, 2, BT_INTEGER
))
2047 if (!less_than_bitsize1 ("I", i
, "SIZE", size
, true))
2050 if (size
->expr_type
== EXPR_CONSTANT
)
2052 gfc_extract_int (size
, &i3
);
2055 gfc_error ("SIZE at %L must be positive", &size
->where
);
2059 if (shift
->expr_type
== EXPR_CONSTANT
)
2061 gfc_extract_int (shift
, &i2
);
2067 gfc_error ("The absolute value of SHIFT at %L must be less "
2068 "than or equal to SIZE at %L", &shift
->where
,
2075 else if (!less_than_bitsize1 ("I", i
, NULL
, shift
, true))
2083 gfc_check_kill (gfc_expr
*pid
, gfc_expr
*sig
)
2085 if (!type_check (pid
, 0, BT_INTEGER
))
2088 if (!type_check (sig
, 1, BT_INTEGER
))
2096 gfc_check_kill_sub (gfc_expr
*pid
, gfc_expr
*sig
, gfc_expr
*status
)
2098 if (!type_check (pid
, 0, BT_INTEGER
))
2101 if (!scalar_check (pid
, 0))
2104 if (!type_check (sig
, 1, BT_INTEGER
))
2107 if (!scalar_check (sig
, 1))
2113 if (!type_check (status
, 2, BT_INTEGER
))
2116 if (!scalar_check (status
, 2))
2124 gfc_check_kind (gfc_expr
*x
)
2126 if (x
->ts
.type
== BT_DERIVED
)
2128 gfc_error ("'%s' argument of '%s' intrinsic at %L must be a "
2129 "non-derived type", gfc_current_intrinsic_arg
[0]->name
,
2130 gfc_current_intrinsic
, &x
->where
);
2139 gfc_check_lbound (gfc_expr
*array
, gfc_expr
*dim
, gfc_expr
*kind
)
2141 if (!array_check (array
, 0))
2144 if (!dim_check (dim
, 1, false))
2147 if (!dim_rank_check (dim
, array
, 1))
2150 if (!kind_check (kind
, 2, BT_INTEGER
))
2152 if (kind
&& !gfc_notify_std (GFC_STD_F2003
, "'%s' intrinsic "
2153 "with KIND argument at %L",
2154 gfc_current_intrinsic
, &kind
->where
))
2162 gfc_check_lcobound (gfc_expr
*coarray
, gfc_expr
*dim
, gfc_expr
*kind
)
2164 if (gfc_option
.coarray
== GFC_FCOARRAY_NONE
)
2166 gfc_fatal_error ("Coarrays disabled at %C, use -fcoarray= to enable");
2170 if (!coarray_check (coarray
, 0))
2175 if (!dim_check (dim
, 1, false))
2178 if (!dim_corank_check (dim
, coarray
))
2182 if (!kind_check (kind
, 2, BT_INTEGER
))
2190 gfc_check_len_lentrim (gfc_expr
*s
, gfc_expr
*kind
)
2192 if (!type_check (s
, 0, BT_CHARACTER
))
2195 if (!kind_check (kind
, 1, BT_INTEGER
))
2197 if (kind
&& !gfc_notify_std (GFC_STD_F2003
, "'%s' intrinsic "
2198 "with KIND argument at %L",
2199 gfc_current_intrinsic
, &kind
->where
))
2207 gfc_check_lge_lgt_lle_llt (gfc_expr
*a
, gfc_expr
*b
)
2209 if (!type_check (a
, 0, BT_CHARACTER
))
2211 if (!kind_value_check (a
, 0, gfc_default_character_kind
))
2214 if (!type_check (b
, 1, BT_CHARACTER
))
2216 if (!kind_value_check (b
, 1, gfc_default_character_kind
))
2224 gfc_check_link (gfc_expr
*path1
, gfc_expr
*path2
)
2226 if (!type_check (path1
, 0, BT_CHARACTER
))
2228 if (!kind_value_check (path1
, 0, gfc_default_character_kind
))
2231 if (!type_check (path2
, 1, BT_CHARACTER
))
2233 if (!kind_value_check (path2
, 1, gfc_default_character_kind
))
2241 gfc_check_link_sub (gfc_expr
*path1
, gfc_expr
*path2
, gfc_expr
*status
)
2243 if (!type_check (path1
, 0, BT_CHARACTER
))
2245 if (!kind_value_check (path1
, 0, gfc_default_character_kind
))
2248 if (!type_check (path2
, 1, BT_CHARACTER
))
2250 if (!kind_value_check (path2
, 0, gfc_default_character_kind
))
2256 if (!type_check (status
, 2, BT_INTEGER
))
2259 if (!scalar_check (status
, 2))
2267 gfc_check_loc (gfc_expr
*expr
)
2269 return variable_check (expr
, 0, true);
2274 gfc_check_symlnk (gfc_expr
*path1
, gfc_expr
*path2
)
2276 if (!type_check (path1
, 0, BT_CHARACTER
))
2278 if (!kind_value_check (path1
, 0, gfc_default_character_kind
))
2281 if (!type_check (path2
, 1, BT_CHARACTER
))
2283 if (!kind_value_check (path2
, 1, gfc_default_character_kind
))
2291 gfc_check_symlnk_sub (gfc_expr
*path1
, gfc_expr
*path2
, gfc_expr
*status
)
2293 if (!type_check (path1
, 0, BT_CHARACTER
))
2295 if (!kind_value_check (path1
, 0, gfc_default_character_kind
))
2298 if (!type_check (path2
, 1, BT_CHARACTER
))
2300 if (!kind_value_check (path2
, 1, gfc_default_character_kind
))
2306 if (!type_check (status
, 2, BT_INTEGER
))
2309 if (!scalar_check (status
, 2))
2317 gfc_check_logical (gfc_expr
*a
, gfc_expr
*kind
)
2319 if (!type_check (a
, 0, BT_LOGICAL
))
2321 if (!kind_check (kind
, 1, BT_LOGICAL
))
2328 /* Min/max family. */
2331 min_max_args (gfc_actual_arglist
*arg
)
2333 if (arg
== NULL
|| arg
->next
== NULL
)
2335 gfc_error ("Intrinsic '%s' at %L must have at least two arguments",
2336 gfc_current_intrinsic
, gfc_current_intrinsic_where
);
2345 check_rest (bt type
, int kind
, gfc_actual_arglist
*arglist
)
2347 gfc_actual_arglist
*arg
, *tmp
;
2352 if (!min_max_args (arglist
))
2355 for (arg
= arglist
, n
=1; arg
; arg
= arg
->next
, n
++)
2358 if (x
->ts
.type
!= type
|| x
->ts
.kind
!= kind
)
2360 if (x
->ts
.type
== type
)
2362 if (!gfc_notify_std (GFC_STD_GNU
, "Different type "
2363 "kinds at %L", &x
->where
))
2368 gfc_error ("'a%d' argument of '%s' intrinsic at %L must be "
2369 "%s(%d)", n
, gfc_current_intrinsic
, &x
->where
,
2370 gfc_basic_typename (type
), kind
);
2375 for (tmp
= arglist
, m
=1; tmp
!= arg
; tmp
= tmp
->next
, m
++)
2376 if (!gfc_check_conformance (tmp
->expr
, x
,
2377 "arguments 'a%d' and 'a%d' for "
2378 "intrinsic '%s'", m
, n
,
2379 gfc_current_intrinsic
))
2388 gfc_check_min_max (gfc_actual_arglist
*arg
)
2392 if (!min_max_args (arg
))
2397 if (x
->ts
.type
== BT_CHARACTER
)
2399 if (!gfc_notify_std (GFC_STD_F2003
, "'%s' intrinsic "
2400 "with CHARACTER argument at %L",
2401 gfc_current_intrinsic
, &x
->where
))
2404 else if (x
->ts
.type
!= BT_INTEGER
&& x
->ts
.type
!= BT_REAL
)
2406 gfc_error ("'a1' argument of '%s' intrinsic at %L must be INTEGER, "
2407 "REAL or CHARACTER", gfc_current_intrinsic
, &x
->where
);
2411 return check_rest (x
->ts
.type
, x
->ts
.kind
, arg
);
2416 gfc_check_min_max_integer (gfc_actual_arglist
*arg
)
2418 return check_rest (BT_INTEGER
, gfc_default_integer_kind
, arg
);
2423 gfc_check_min_max_real (gfc_actual_arglist
*arg
)
2425 return check_rest (BT_REAL
, gfc_default_real_kind
, arg
);
2430 gfc_check_min_max_double (gfc_actual_arglist
*arg
)
2432 return check_rest (BT_REAL
, gfc_default_double_kind
, arg
);
2436 /* End of min/max family. */
2439 gfc_check_malloc (gfc_expr
*size
)
2441 if (!type_check (size
, 0, BT_INTEGER
))
2444 if (!scalar_check (size
, 0))
2452 gfc_check_matmul (gfc_expr
*matrix_a
, gfc_expr
*matrix_b
)
2454 if ((matrix_a
->ts
.type
!= BT_LOGICAL
) && !gfc_numeric_ts (&matrix_a
->ts
))
2456 gfc_error ("'%s' argument of '%s' intrinsic at %L must be numeric "
2457 "or LOGICAL", gfc_current_intrinsic_arg
[0]->name
,
2458 gfc_current_intrinsic
, &matrix_a
->where
);
2462 if ((matrix_b
->ts
.type
!= BT_LOGICAL
) && !gfc_numeric_ts (&matrix_b
->ts
))
2464 gfc_error ("'%s' argument of '%s' intrinsic at %L must be numeric "
2465 "or LOGICAL", gfc_current_intrinsic_arg
[1]->name
,
2466 gfc_current_intrinsic
, &matrix_b
->where
);
2470 if ((matrix_a
->ts
.type
== BT_LOGICAL
&& gfc_numeric_ts (&matrix_b
->ts
))
2471 || (gfc_numeric_ts (&matrix_a
->ts
) && matrix_b
->ts
.type
== BT_LOGICAL
))
2473 gfc_error ("Argument types of '%s' intrinsic at %L must match (%s/%s)",
2474 gfc_current_intrinsic
, &matrix_a
->where
,
2475 gfc_typename(&matrix_a
->ts
), gfc_typename(&matrix_b
->ts
));
2479 switch (matrix_a
->rank
)
2482 if (!rank_check (matrix_b
, 1, 2))
2484 /* Check for case matrix_a has shape(m), matrix_b has shape (m, k). */
2485 if (!identical_dimen_shape (matrix_a
, 0, matrix_b
, 0))
2487 gfc_error ("Different shape on dimension 1 for arguments '%s' "
2488 "and '%s' at %L for intrinsic matmul",
2489 gfc_current_intrinsic_arg
[0]->name
,
2490 gfc_current_intrinsic_arg
[1]->name
, &matrix_a
->where
);
2496 if (matrix_b
->rank
!= 2)
2498 if (!rank_check (matrix_b
, 1, 1))
2501 /* matrix_b has rank 1 or 2 here. Common check for the cases
2502 - matrix_a has shape (n,m) and matrix_b has shape (m, k)
2503 - matrix_a has shape (n,m) and matrix_b has shape (m). */
2504 if (!identical_dimen_shape (matrix_a
, 1, matrix_b
, 0))
2506 gfc_error ("Different shape on dimension 2 for argument '%s' and "
2507 "dimension 1 for argument '%s' at %L for intrinsic "
2508 "matmul", gfc_current_intrinsic_arg
[0]->name
,
2509 gfc_current_intrinsic_arg
[1]->name
, &matrix_a
->where
);
2515 gfc_error ("'%s' argument of '%s' intrinsic at %L must be of rank "
2516 "1 or 2", gfc_current_intrinsic_arg
[0]->name
,
2517 gfc_current_intrinsic
, &matrix_a
->where
);
2525 /* Whoever came up with this interface was probably on something.
2526 The possibilities for the occupation of the second and third
2533 NULL MASK minloc(array, mask=m)
2536 I.e. in the case of minloc(array,mask), mask will be in the second
2537 position of the argument list and we'll have to fix that up. */
2540 gfc_check_minloc_maxloc (gfc_actual_arglist
*ap
)
2542 gfc_expr
*a
, *m
, *d
;
2545 if (!int_or_real_check (a
, 0) || !array_check (a
, 0))
2549 m
= ap
->next
->next
->expr
;
2551 if (m
== NULL
&& d
!= NULL
&& d
->ts
.type
== BT_LOGICAL
2552 && ap
->next
->name
== NULL
)
2556 ap
->next
->expr
= NULL
;
2557 ap
->next
->next
->expr
= m
;
2560 if (!dim_check (d
, 1, false))
2563 if (!dim_rank_check (d
, a
, 0))
2566 if (m
!= NULL
&& !type_check (m
, 2, BT_LOGICAL
))
2570 && !gfc_check_conformance (a
, m
,
2571 "arguments '%s' and '%s' for intrinsic %s",
2572 gfc_current_intrinsic_arg
[0]->name
,
2573 gfc_current_intrinsic_arg
[2]->name
,
2574 gfc_current_intrinsic
))
2581 /* Similar to minloc/maxloc, the argument list might need to be
2582 reordered for the MINVAL, MAXVAL, PRODUCT, and SUM intrinsics. The
2583 difference is that MINLOC/MAXLOC take an additional KIND argument.
2584 The possibilities are:
2590 NULL MASK minval(array, mask=m)
2593 I.e. in the case of minval(array,mask), mask will be in the second
2594 position of the argument list and we'll have to fix that up. */
2597 check_reduction (gfc_actual_arglist
*ap
)
2599 gfc_expr
*a
, *m
, *d
;
2603 m
= ap
->next
->next
->expr
;
2605 if (m
== NULL
&& d
!= NULL
&& d
->ts
.type
== BT_LOGICAL
2606 && ap
->next
->name
== NULL
)
2610 ap
->next
->expr
= NULL
;
2611 ap
->next
->next
->expr
= m
;
2614 if (!dim_check (d
, 1, false))
2617 if (!dim_rank_check (d
, a
, 0))
2620 if (m
!= NULL
&& !type_check (m
, 2, BT_LOGICAL
))
2624 && !gfc_check_conformance (a
, m
,
2625 "arguments '%s' and '%s' for intrinsic %s",
2626 gfc_current_intrinsic_arg
[0]->name
,
2627 gfc_current_intrinsic_arg
[2]->name
,
2628 gfc_current_intrinsic
))
2636 gfc_check_minval_maxval (gfc_actual_arglist
*ap
)
2638 if (!int_or_real_check (ap
->expr
, 0)
2639 || !array_check (ap
->expr
, 0))
2642 return check_reduction (ap
);
2647 gfc_check_product_sum (gfc_actual_arglist
*ap
)
2649 if (!numeric_check (ap
->expr
, 0)
2650 || !array_check (ap
->expr
, 0))
2653 return check_reduction (ap
);
2657 /* For IANY, IALL and IPARITY. */
2660 gfc_check_mask (gfc_expr
*i
, gfc_expr
*kind
)
2664 if (!type_check (i
, 0, BT_INTEGER
))
2667 if (!nonnegative_check ("I", i
))
2670 if (!kind_check (kind
, 1, BT_INTEGER
))
2674 gfc_extract_int (kind
, &k
);
2676 k
= gfc_default_integer_kind
;
2678 if (!less_than_bitsizekind ("I", i
, k
))
2686 gfc_check_transf_bit_intrins (gfc_actual_arglist
*ap
)
2688 if (ap
->expr
->ts
.type
!= BT_INTEGER
)
2690 gfc_error ("'%s' argument of '%s' intrinsic at %L must be INTEGER",
2691 gfc_current_intrinsic_arg
[0]->name
,
2692 gfc_current_intrinsic
, &ap
->expr
->where
);
2696 if (!array_check (ap
->expr
, 0))
2699 return check_reduction (ap
);
2704 gfc_check_merge (gfc_expr
*tsource
, gfc_expr
*fsource
, gfc_expr
*mask
)
2706 if (!same_type_check (tsource
, 0, fsource
, 1))
2709 if (!type_check (mask
, 2, BT_LOGICAL
))
2712 if (tsource
->ts
.type
== BT_CHARACTER
)
2713 return gfc_check_same_strlen (tsource
, fsource
, "MERGE intrinsic");
2720 gfc_check_merge_bits (gfc_expr
*i
, gfc_expr
*j
, gfc_expr
*mask
)
2722 if (!type_check (i
, 0, BT_INTEGER
))
2725 if (!type_check (j
, 1, BT_INTEGER
))
2728 if (!type_check (mask
, 2, BT_INTEGER
))
2731 if (!same_type_check (i
, 0, j
, 1))
2734 if (!same_type_check (i
, 0, mask
, 2))
2742 gfc_check_move_alloc (gfc_expr
*from
, gfc_expr
*to
)
2744 if (!variable_check (from
, 0, false))
2746 if (!allocatable_check (from
, 0))
2748 if (gfc_is_coindexed (from
))
2750 gfc_error ("The FROM argument to MOVE_ALLOC at %L shall not be "
2751 "coindexed", &from
->where
);
2755 if (!variable_check (to
, 1, false))
2757 if (!allocatable_check (to
, 1))
2759 if (gfc_is_coindexed (to
))
2761 gfc_error ("The TO argument to MOVE_ALLOC at %L shall not be "
2762 "coindexed", &to
->where
);
2766 if (from
->ts
.type
== BT_CLASS
&& to
->ts
.type
== BT_DERIVED
)
2768 gfc_error ("The TO arguments in MOVE_ALLOC at %L must be "
2769 "polymorphic if FROM is polymorphic",
2774 if (!same_type_check (to
, 1, from
, 0))
2777 if (to
->rank
!= from
->rank
)
2779 gfc_error ("The FROM and TO arguments of the MOVE_ALLOC intrinsic at %L "
2780 "must have the same rank %d/%d", &to
->where
, from
->rank
,
2785 /* IR F08/0040; cf. 12-006A. */
2786 if (gfc_get_corank (to
) != gfc_get_corank (from
))
2788 gfc_error ("The FROM and TO arguments of the MOVE_ALLOC intrinsic at %L "
2789 "must have the same corank %d/%d", &to
->where
,
2790 gfc_get_corank (from
), gfc_get_corank (to
));
2794 /* CLASS arguments: Make sure the vtab of from is present. */
2795 if (to
->ts
.type
== BT_CLASS
&& !UNLIMITED_POLY (from
))
2797 if (from
->ts
.type
== BT_CLASS
|| from
->ts
.type
== BT_DERIVED
)
2798 gfc_find_derived_vtab (from
->ts
.u
.derived
);
2800 gfc_find_intrinsic_vtab (&from
->ts
);
2808 gfc_check_nearest (gfc_expr
*x
, gfc_expr
*s
)
2810 if (!type_check (x
, 0, BT_REAL
))
2813 if (!type_check (s
, 1, BT_REAL
))
2816 if (s
->expr_type
== EXPR_CONSTANT
)
2818 if (mpfr_sgn (s
->value
.real
) == 0)
2820 gfc_error ("Argument 'S' of NEAREST at %L shall not be zero",
2831 gfc_check_new_line (gfc_expr
*a
)
2833 if (!type_check (a
, 0, BT_CHARACTER
))
2841 gfc_check_norm2 (gfc_expr
*array
, gfc_expr
*dim
)
2843 if (!type_check (array
, 0, BT_REAL
))
2846 if (!array_check (array
, 0))
2849 if (!dim_rank_check (dim
, array
, false))
2856 gfc_check_null (gfc_expr
*mold
)
2858 symbol_attribute attr
;
2863 if (!variable_check (mold
, 0, true))
2866 attr
= gfc_variable_attr (mold
, NULL
);
2868 if (!attr
.pointer
&& !attr
.proc_pointer
&& !attr
.allocatable
)
2870 gfc_error ("'%s' argument of '%s' intrinsic at %L must be a POINTER, "
2871 "ALLOCATABLE or procedure pointer",
2872 gfc_current_intrinsic_arg
[0]->name
,
2873 gfc_current_intrinsic
, &mold
->where
);
2877 if (attr
.allocatable
2878 && !gfc_notify_std (GFC_STD_F2003
, "NULL intrinsic with "
2879 "allocatable MOLD at %L", &mold
->where
))
2883 if (gfc_is_coindexed (mold
))
2885 gfc_error ("'%s' argument of '%s' intrinsic at %L shall not be "
2886 "coindexed", gfc_current_intrinsic_arg
[0]->name
,
2887 gfc_current_intrinsic
, &mold
->where
);
2896 gfc_check_pack (gfc_expr
*array
, gfc_expr
*mask
, gfc_expr
*vector
)
2898 if (!array_check (array
, 0))
2901 if (!type_check (mask
, 1, BT_LOGICAL
))
2904 if (!gfc_check_conformance (array
, mask
,
2905 "arguments '%s' and '%s' for intrinsic '%s'",
2906 gfc_current_intrinsic_arg
[0]->name
,
2907 gfc_current_intrinsic_arg
[1]->name
,
2908 gfc_current_intrinsic
))
2913 mpz_t array_size
, vector_size
;
2914 bool have_array_size
, have_vector_size
;
2916 if (!same_type_check (array
, 0, vector
, 2))
2919 if (!rank_check (vector
, 2, 1))
2922 /* VECTOR requires at least as many elements as MASK
2923 has .TRUE. values. */
2924 have_array_size
= gfc_array_size(array
, &array_size
);
2925 have_vector_size
= gfc_array_size(vector
, &vector_size
);
2927 if (have_vector_size
2928 && (mask
->expr_type
== EXPR_ARRAY
2929 || (mask
->expr_type
== EXPR_CONSTANT
2930 && have_array_size
)))
2932 int mask_true_values
= 0;
2934 if (mask
->expr_type
== EXPR_ARRAY
)
2936 gfc_constructor
*mask_ctor
;
2937 mask_ctor
= gfc_constructor_first (mask
->value
.constructor
);
2940 if (mask_ctor
->expr
->expr_type
!= EXPR_CONSTANT
)
2942 mask_true_values
= 0;
2946 if (mask_ctor
->expr
->value
.logical
)
2949 mask_ctor
= gfc_constructor_next (mask_ctor
);
2952 else if (mask
->expr_type
== EXPR_CONSTANT
&& mask
->value
.logical
)
2953 mask_true_values
= mpz_get_si (array_size
);
2955 if (mpz_get_si (vector_size
) < mask_true_values
)
2957 gfc_error ("'%s' argument of '%s' intrinsic at %L must "
2958 "provide at least as many elements as there "
2959 "are .TRUE. values in '%s' (%ld/%d)",
2960 gfc_current_intrinsic_arg
[2]->name
,
2961 gfc_current_intrinsic
, &vector
->where
,
2962 gfc_current_intrinsic_arg
[1]->name
,
2963 mpz_get_si (vector_size
), mask_true_values
);
2968 if (have_array_size
)
2969 mpz_clear (array_size
);
2970 if (have_vector_size
)
2971 mpz_clear (vector_size
);
2979 gfc_check_parity (gfc_expr
*mask
, gfc_expr
*dim
)
2981 if (!type_check (mask
, 0, BT_LOGICAL
))
2984 if (!array_check (mask
, 0))
2987 if (!dim_rank_check (dim
, mask
, false))
2995 gfc_check_precision (gfc_expr
*x
)
2997 if (!real_or_complex_check (x
, 0))
3005 gfc_check_present (gfc_expr
*a
)
3009 if (!variable_check (a
, 0, true))
3012 sym
= a
->symtree
->n
.sym
;
3013 if (!sym
->attr
.dummy
)
3015 gfc_error ("'%s' argument of '%s' intrinsic at %L must be of a "
3016 "dummy variable", gfc_current_intrinsic_arg
[0]->name
,
3017 gfc_current_intrinsic
, &a
->where
);
3021 if (!sym
->attr
.optional
)
3023 gfc_error ("'%s' argument of '%s' intrinsic at %L must be of "
3024 "an OPTIONAL dummy variable",
3025 gfc_current_intrinsic_arg
[0]->name
, gfc_current_intrinsic
,
3030 /* 13.14.82 PRESENT(A)
3032 Argument. A shall be the name of an optional dummy argument that is
3033 accessible in the subprogram in which the PRESENT function reference
3037 && !(a
->ref
->next
== NULL
&& a
->ref
->type
== REF_ARRAY
3038 && (a
->ref
->u
.ar
.type
== AR_FULL
3039 || (a
->ref
->u
.ar
.type
== AR_ELEMENT
3040 && a
->ref
->u
.ar
.as
->rank
== 0))))
3042 gfc_error ("'%s' argument of '%s' intrinsic at %L must not be a "
3043 "subobject of '%s'", gfc_current_intrinsic_arg
[0]->name
,
3044 gfc_current_intrinsic
, &a
->where
, sym
->name
);
3053 gfc_check_radix (gfc_expr
*x
)
3055 if (!int_or_real_check (x
, 0))
3063 gfc_check_range (gfc_expr
*x
)
3065 if (!numeric_check (x
, 0))
3073 gfc_check_rank (gfc_expr
*a ATTRIBUTE_UNUSED
)
3075 /* Any data object is allowed; a "data object" is a "constant (4.1.3),
3076 variable (6), or subobject of a constant (2.4.3.2.3)" (F2008, 1.3.45). */
3078 bool is_variable
= true;
3080 /* Functions returning pointers are regarded as variable, cf. F2008, R602. */
3081 if (a
->expr_type
== EXPR_FUNCTION
)
3082 is_variable
= a
->value
.function
.esym
3083 ? a
->value
.function
.esym
->result
->attr
.pointer
3084 : a
->symtree
->n
.sym
->result
->attr
.pointer
;
3086 if (a
->expr_type
== EXPR_OP
|| a
->expr_type
== EXPR_NULL
3087 || a
->expr_type
== EXPR_COMPCALL
|| a
->expr_type
== EXPR_PPC
3090 gfc_error ("The argument of the RANK intrinsic at %L must be a data "
3091 "object", &a
->where
);
3099 /* real, float, sngl. */
3101 gfc_check_real (gfc_expr
*a
, gfc_expr
*kind
)
3103 if (!numeric_check (a
, 0))
3106 if (!kind_check (kind
, 1, BT_REAL
))
3114 gfc_check_rename (gfc_expr
*path1
, gfc_expr
*path2
)
3116 if (!type_check (path1
, 0, BT_CHARACTER
))
3118 if (!kind_value_check (path1
, 0, gfc_default_character_kind
))
3121 if (!type_check (path2
, 1, BT_CHARACTER
))
3123 if (!kind_value_check (path2
, 1, gfc_default_character_kind
))
3131 gfc_check_rename_sub (gfc_expr
*path1
, gfc_expr
*path2
, gfc_expr
*status
)
3133 if (!type_check (path1
, 0, BT_CHARACTER
))
3135 if (!kind_value_check (path1
, 0, gfc_default_character_kind
))
3138 if (!type_check (path2
, 1, BT_CHARACTER
))
3140 if (!kind_value_check (path2
, 1, gfc_default_character_kind
))
3146 if (!type_check (status
, 2, BT_INTEGER
))
3149 if (!scalar_check (status
, 2))
3157 gfc_check_repeat (gfc_expr
*x
, gfc_expr
*y
)
3159 if (!type_check (x
, 0, BT_CHARACTER
))
3162 if (!scalar_check (x
, 0))
3165 if (!type_check (y
, 0, BT_INTEGER
))
3168 if (!scalar_check (y
, 1))
3176 gfc_check_reshape (gfc_expr
*source
, gfc_expr
*shape
,
3177 gfc_expr
*pad
, gfc_expr
*order
)
3183 if (!array_check (source
, 0))
3186 if (!rank_check (shape
, 1, 1))
3189 if (!type_check (shape
, 1, BT_INTEGER
))
3192 if (!gfc_array_size (shape
, &size
))
3194 gfc_error ("'shape' argument of 'reshape' intrinsic at %L must be an "
3195 "array of constant size", &shape
->where
);
3199 shape_size
= mpz_get_ui (size
);
3202 if (shape_size
<= 0)
3204 gfc_error ("'%s' argument of '%s' intrinsic at %L is empty",
3205 gfc_current_intrinsic_arg
[1]->name
, gfc_current_intrinsic
,
3209 else if (shape_size
> GFC_MAX_DIMENSIONS
)
3211 gfc_error ("'shape' argument of 'reshape' intrinsic at %L has more "
3212 "than %d elements", &shape
->where
, GFC_MAX_DIMENSIONS
);
3215 else if (shape
->expr_type
== EXPR_ARRAY
)
3219 for (i
= 0; i
< shape_size
; ++i
)
3221 e
= gfc_constructor_lookup_expr (shape
->value
.constructor
, i
);
3222 if (e
->expr_type
!= EXPR_CONSTANT
)
3225 gfc_extract_int (e
, &extent
);
3228 gfc_error ("'%s' argument of '%s' intrinsic at %L has "
3229 "negative element (%d)",
3230 gfc_current_intrinsic_arg
[1]->name
,
3231 gfc_current_intrinsic
, &e
->where
, extent
);
3239 if (!same_type_check (source
, 0, pad
, 2))
3242 if (!array_check (pad
, 2))
3248 if (!array_check (order
, 3))
3251 if (!type_check (order
, 3, BT_INTEGER
))
3254 if (order
->expr_type
== EXPR_ARRAY
)
3256 int i
, order_size
, dim
, perm
[GFC_MAX_DIMENSIONS
];
3259 for (i
= 0; i
< GFC_MAX_DIMENSIONS
; ++i
)
3262 gfc_array_size (order
, &size
);
3263 order_size
= mpz_get_ui (size
);
3266 if (order_size
!= shape_size
)
3268 gfc_error ("'%s' argument of '%s' intrinsic at %L "
3269 "has wrong number of elements (%d/%d)",
3270 gfc_current_intrinsic_arg
[3]->name
,
3271 gfc_current_intrinsic
, &order
->where
,
3272 order_size
, shape_size
);
3276 for (i
= 1; i
<= order_size
; ++i
)
3278 e
= gfc_constructor_lookup_expr (order
->value
.constructor
, i
-1);
3279 if (e
->expr_type
!= EXPR_CONSTANT
)
3282 gfc_extract_int (e
, &dim
);
3284 if (dim
< 1 || dim
> order_size
)
3286 gfc_error ("'%s' argument of '%s' intrinsic at %L "
3287 "has out-of-range dimension (%d)",
3288 gfc_current_intrinsic_arg
[3]->name
,
3289 gfc_current_intrinsic
, &e
->where
, dim
);
3293 if (perm
[dim
-1] != 0)
3295 gfc_error ("'%s' argument of '%s' intrinsic at %L has "
3296 "invalid permutation of dimensions (dimension "
3298 gfc_current_intrinsic_arg
[3]->name
,
3299 gfc_current_intrinsic
, &e
->where
, dim
);
3308 if (pad
== NULL
&& shape
->expr_type
== EXPR_ARRAY
3309 && gfc_is_constant_expr (shape
)
3310 && !(source
->expr_type
== EXPR_VARIABLE
&& source
->symtree
->n
.sym
->as
3311 && source
->symtree
->n
.sym
->as
->type
== AS_ASSUMED_SIZE
))
3313 /* Check the match in size between source and destination. */
3314 if (gfc_array_size (source
, &nelems
))
3320 mpz_init_set_ui (size
, 1);
3321 for (c
= gfc_constructor_first (shape
->value
.constructor
);
3322 c
; c
= gfc_constructor_next (c
))
3323 mpz_mul (size
, size
, c
->expr
->value
.integer
);
3325 test
= mpz_cmp (nelems
, size
) < 0 && mpz_cmp_ui (size
, 0) > 0;
3331 gfc_error ("Without padding, there are not enough elements "
3332 "in the intrinsic RESHAPE source at %L to match "
3333 "the shape", &source
->where
);
3344 gfc_check_same_type_as (gfc_expr
*a
, gfc_expr
*b
)
3346 if (a
->ts
.type
!= BT_DERIVED
&& a
->ts
.type
!= BT_CLASS
)
3348 gfc_error ("'%s' argument of '%s' intrinsic at %L "
3349 "cannot be of type %s",
3350 gfc_current_intrinsic_arg
[0]->name
,
3351 gfc_current_intrinsic
,
3352 &a
->where
, gfc_typename (&a
->ts
));
3356 if (!(gfc_type_is_extensible (a
->ts
.u
.derived
) || UNLIMITED_POLY (a
)))
3358 gfc_error ("'%s' argument of '%s' intrinsic at %L "
3359 "must be of an extensible type",
3360 gfc_current_intrinsic_arg
[0]->name
, gfc_current_intrinsic
,
3365 if (b
->ts
.type
!= BT_DERIVED
&& b
->ts
.type
!= BT_CLASS
)
3367 gfc_error ("'%s' argument of '%s' intrinsic at %L "
3368 "cannot be of type %s",
3369 gfc_current_intrinsic_arg
[0]->name
,
3370 gfc_current_intrinsic
,
3371 &b
->where
, gfc_typename (&b
->ts
));
3375 if (!(gfc_type_is_extensible (b
->ts
.u
.derived
) || UNLIMITED_POLY (b
)))
3377 gfc_error ("'%s' argument of '%s' intrinsic at %L "
3378 "must be of an extensible type",
3379 gfc_current_intrinsic_arg
[1]->name
, gfc_current_intrinsic
,
3389 gfc_check_scale (gfc_expr
*x
, gfc_expr
*i
)
3391 if (!type_check (x
, 0, BT_REAL
))
3394 if (!type_check (i
, 1, BT_INTEGER
))
3402 gfc_check_scan (gfc_expr
*x
, gfc_expr
*y
, gfc_expr
*z
, gfc_expr
*kind
)
3404 if (!type_check (x
, 0, BT_CHARACTER
))
3407 if (!type_check (y
, 1, BT_CHARACTER
))
3410 if (z
!= NULL
&& !type_check (z
, 2, BT_LOGICAL
))
3413 if (!kind_check (kind
, 3, BT_INTEGER
))
3415 if (kind
&& !gfc_notify_std (GFC_STD_F2003
, "'%s' intrinsic "
3416 "with KIND argument at %L",
3417 gfc_current_intrinsic
, &kind
->where
))
3420 if (!same_type_check (x
, 0, y
, 1))
3428 gfc_check_secnds (gfc_expr
*r
)
3430 if (!type_check (r
, 0, BT_REAL
))
3433 if (!kind_value_check (r
, 0, 4))
3436 if (!scalar_check (r
, 0))
3444 gfc_check_selected_char_kind (gfc_expr
*name
)
3446 if (!type_check (name
, 0, BT_CHARACTER
))
3449 if (!kind_value_check (name
, 0, gfc_default_character_kind
))
3452 if (!scalar_check (name
, 0))
3460 gfc_check_selected_int_kind (gfc_expr
*r
)
3462 if (!type_check (r
, 0, BT_INTEGER
))
3465 if (!scalar_check (r
, 0))
3473 gfc_check_selected_real_kind (gfc_expr
*p
, gfc_expr
*r
, gfc_expr
*radix
)
3475 if (p
== NULL
&& r
== NULL
3476 && !gfc_notify_std (GFC_STD_F2008
, "SELECTED_REAL_KIND with"
3477 " neither 'P' nor 'R' argument at %L",
3478 gfc_current_intrinsic_where
))
3483 if (!type_check (p
, 0, BT_INTEGER
))
3486 if (!scalar_check (p
, 0))
3492 if (!type_check (r
, 1, BT_INTEGER
))
3495 if (!scalar_check (r
, 1))
3501 if (!type_check (radix
, 1, BT_INTEGER
))
3504 if (!scalar_check (radix
, 1))
3507 if (!gfc_notify_std (GFC_STD_F2008
, "'%s' intrinsic with "
3508 "RADIX argument at %L", gfc_current_intrinsic
,
3518 gfc_check_set_exponent (gfc_expr
*x
, gfc_expr
*i
)
3520 if (!type_check (x
, 0, BT_REAL
))
3523 if (!type_check (i
, 1, BT_INTEGER
))
3531 gfc_check_shape (gfc_expr
*source
, gfc_expr
*kind
)
3535 if (source
->rank
== 0 || source
->expr_type
!= EXPR_VARIABLE
)
3538 ar
= gfc_find_array_ref (source
);
3540 if (ar
->as
&& ar
->as
->type
== AS_ASSUMED_SIZE
&& ar
->type
== AR_FULL
)
3542 gfc_error ("'source' argument of 'shape' intrinsic at %L must not be "
3543 "an assumed size array", &source
->where
);
3547 if (!kind_check (kind
, 1, BT_INTEGER
))
3549 if (kind
&& !gfc_notify_std (GFC_STD_F2003
, "'%s' intrinsic "
3550 "with KIND argument at %L",
3551 gfc_current_intrinsic
, &kind
->where
))
3559 gfc_check_shift (gfc_expr
*i
, gfc_expr
*shift
)
3561 if (!type_check (i
, 0, BT_INTEGER
))
3564 if (!type_check (shift
, 0, BT_INTEGER
))
3567 if (!nonnegative_check ("SHIFT", shift
))
3570 if (!less_than_bitsize1 ("I", i
, "SHIFT", shift
, true))
3578 gfc_check_sign (gfc_expr
*a
, gfc_expr
*b
)
3580 if (!int_or_real_check (a
, 0))
3583 if (!same_type_check (a
, 0, b
, 1))
3591 gfc_check_size (gfc_expr
*array
, gfc_expr
*dim
, gfc_expr
*kind
)
3593 if (!array_check (array
, 0))
3596 if (!dim_check (dim
, 1, true))
3599 if (!dim_rank_check (dim
, array
, 0))
3602 if (!kind_check (kind
, 2, BT_INTEGER
))
3604 if (kind
&& !gfc_notify_std (GFC_STD_F2003
, "'%s' intrinsic "
3605 "with KIND argument at %L",
3606 gfc_current_intrinsic
, &kind
->where
))
3615 gfc_check_sizeof (gfc_expr
*arg
)
3617 if (arg
->ts
.type
== BT_PROCEDURE
)
3619 gfc_error ("'%s' argument of '%s' intrinsic at %L shall not be a procedure",
3620 gfc_current_intrinsic_arg
[0]->name
, gfc_current_intrinsic
,
3625 if (arg
->ts
.type
== BT_ASSUMED
)
3627 gfc_error ("'%s' argument of '%s' intrinsic at %L shall not be TYPE(*)",
3628 gfc_current_intrinsic_arg
[0]->name
, gfc_current_intrinsic
,
3633 if (arg
->rank
&& arg
->expr_type
== EXPR_VARIABLE
3634 && arg
->symtree
->n
.sym
->as
!= NULL
3635 && arg
->symtree
->n
.sym
->as
->type
== AS_ASSUMED_SIZE
&& arg
->ref
3636 && arg
->ref
->type
== REF_ARRAY
&& arg
->ref
->u
.ar
.type
== AR_FULL
)
3638 gfc_error ("'%s' argument of '%s' intrinsic at %L shall not be an "
3639 "assumed-size array", gfc_current_intrinsic_arg
[0]->name
,
3640 gfc_current_intrinsic
, &arg
->where
);
3648 /* Check whether an expression is interoperable. When returning false,
3649 msg is set to a string telling why the expression is not interoperable,
3650 otherwise, it is set to NULL. The msg string can be used in diagnostics.
3651 If c_loc is true, character with len > 1 are allowed (cf. Fortran
3652 2003corr5); additionally, assumed-shape/assumed-rank/deferred-shape
3653 arrays are permitted. */
3656 is_c_interoperable (gfc_expr
*expr
, const char **msg
, bool c_loc
)
3660 if (expr
->ts
.type
== BT_CLASS
)
3662 *msg
= "Expression is polymorphic";
3666 if (expr
->ts
.type
== BT_DERIVED
&& !expr
->ts
.u
.derived
->attr
.is_bind_c
3667 && !expr
->ts
.u
.derived
->ts
.is_iso_c
)
3669 *msg
= "Expression is a noninteroperable derived type";
3673 if (expr
->ts
.type
== BT_PROCEDURE
)
3675 *msg
= "Procedure unexpected as argument";
3679 if (gfc_notification_std (GFC_STD_GNU
) && expr
->ts
.type
== BT_LOGICAL
)
3682 for (i
= 0; gfc_logical_kinds
[i
].kind
; i
++)
3683 if (gfc_logical_kinds
[i
].kind
== expr
->ts
.kind
)
3685 *msg
= "Extension to use a non-C_Bool-kind LOGICAL";
3689 if (gfc_notification_std (GFC_STD_GNU
) && expr
->ts
.type
== BT_CHARACTER
3690 && expr
->ts
.kind
!= 1)
3692 *msg
= "Extension to use a non-C_CHAR-kind CHARACTER";
3696 if (expr
->ts
.type
== BT_CHARACTER
) {
3697 if (expr
->ts
.deferred
)
3699 /* TS 29113 allows deferred-length strings as dummy arguments,
3700 but it is not an interoperable type. */
3701 *msg
= "Expression shall not be a deferred-length string";
3705 if (expr
->ts
.u
.cl
&& expr
->ts
.u
.cl
->length
3706 && !gfc_simplify_expr (expr
, 0))
3707 gfc_internal_error ("is_c_interoperable(): gfc_simplify_expr failed");
3709 if (!c_loc
&& expr
->ts
.u
.cl
3710 && (!expr
->ts
.u
.cl
->length
3711 || expr
->ts
.u
.cl
->length
->expr_type
!= EXPR_CONSTANT
3712 || mpz_cmp_si (expr
->ts
.u
.cl
->length
->value
.integer
, 1) != 0))
3714 *msg
= "Type shall have a character length of 1";
3719 /* Note: The following checks are about interoperatable variables, Fortran
3720 15.3.5/15.3.6. In intrinsics like C_LOC or in procedure interface, more
3721 is allowed, e.g. assumed-shape arrays with TS 29113. */
3723 if (gfc_is_coarray (expr
))
3725 *msg
= "Coarrays are not interoperable";
3729 if (!c_loc
&& expr
->rank
> 0 && expr
->expr_type
!= EXPR_ARRAY
)
3731 gfc_array_ref
*ar
= gfc_find_array_ref (expr
);
3732 if (ar
->type
!= AR_FULL
)
3734 *msg
= "Only whole-arrays are interoperable";
3737 if (ar
->as
->type
!= AS_EXPLICIT
&& ar
->as
->type
!= AS_ASSUMED_SIZE
)
3739 *msg
= "Only explicit-size and assumed-size arrays are interoperable";
3749 gfc_check_c_sizeof (gfc_expr
*arg
)
3753 if (!is_c_interoperable (arg
, &msg
, false))
3755 gfc_error ("'%s' argument of '%s' intrinsic at %L must be an "
3756 "interoperable data entity: %s",
3757 gfc_current_intrinsic_arg
[0]->name
, gfc_current_intrinsic
,
3762 if (arg
->ts
.type
== BT_ASSUMED
)
3764 gfc_error ("'%s' argument of '%s' intrinsic at %L shall not be "
3766 gfc_current_intrinsic_arg
[0]->name
, gfc_current_intrinsic
,
3771 if (arg
->rank
&& arg
->expr_type
== EXPR_VARIABLE
3772 && arg
->symtree
->n
.sym
->as
!= NULL
3773 && arg
->symtree
->n
.sym
->as
->type
== AS_ASSUMED_SIZE
&& arg
->ref
3774 && arg
->ref
->type
== REF_ARRAY
&& arg
->ref
->u
.ar
.type
== AR_FULL
)
3776 gfc_error ("'%s' argument of '%s' intrinsic at %L shall not be an "
3777 "assumed-size array", gfc_current_intrinsic_arg
[0]->name
,
3778 gfc_current_intrinsic
, &arg
->where
);
3787 gfc_check_c_associated (gfc_expr
*c_ptr_1
, gfc_expr
*c_ptr_2
)
3789 if (c_ptr_1
->ts
.type
!= BT_DERIVED
3790 || c_ptr_1
->ts
.u
.derived
->from_intmod
!= INTMOD_ISO_C_BINDING
3791 || (c_ptr_1
->ts
.u
.derived
->intmod_sym_id
!= ISOCBINDING_PTR
3792 && c_ptr_1
->ts
.u
.derived
->intmod_sym_id
!= ISOCBINDING_FUNPTR
))
3794 gfc_error ("Argument C_PTR_1 at %L to C_ASSOCIATED shall have the "
3795 "type TYPE(C_PTR) or TYPE(C_FUNPTR)", &c_ptr_1
->where
);
3799 if (!scalar_check (c_ptr_1
, 0))
3803 && (c_ptr_2
->ts
.type
!= BT_DERIVED
3804 || c_ptr_2
->ts
.u
.derived
->from_intmod
!= INTMOD_ISO_C_BINDING
3805 || (c_ptr_1
->ts
.u
.derived
->intmod_sym_id
3806 != c_ptr_2
->ts
.u
.derived
->intmod_sym_id
)))
3808 gfc_error ("Argument C_PTR_2 at %L to C_ASSOCIATED shall have the "
3809 "same type as C_PTR_1: %s instead of %s", &c_ptr_1
->where
,
3810 gfc_typename (&c_ptr_1
->ts
),
3811 gfc_typename (&c_ptr_2
->ts
));
3815 if (c_ptr_2
&& !scalar_check (c_ptr_2
, 1))
3823 gfc_check_c_f_pointer (gfc_expr
*cptr
, gfc_expr
*fptr
, gfc_expr
*shape
)
3825 symbol_attribute attr
;
3828 if (cptr
->ts
.type
!= BT_DERIVED
3829 || cptr
->ts
.u
.derived
->from_intmod
!= INTMOD_ISO_C_BINDING
3830 || cptr
->ts
.u
.derived
->intmod_sym_id
!= ISOCBINDING_PTR
)
3832 gfc_error ("Argument CPTR at %L to C_F_POINTER shall have the "
3833 "type TYPE(C_PTR)", &cptr
->where
);
3837 if (!scalar_check (cptr
, 0))
3840 attr
= gfc_expr_attr (fptr
);
3844 gfc_error ("Argument FPTR at %L to C_F_POINTER must be a pointer",
3849 if (fptr
->ts
.type
== BT_CLASS
)
3851 gfc_error ("FPTR argument at %L to C_F_POINTER shall not be polymorphic",
3856 if (gfc_is_coindexed (fptr
))
3858 gfc_error ("Argument FPTR at %L to C_F_POINTER shall not be "
3859 "coindexed", &fptr
->where
);
3863 if (fptr
->rank
== 0 && shape
)
3865 gfc_error ("Unexpected SHAPE argument at %L to C_F_POINTER with scalar "
3866 "FPTR", &fptr
->where
);
3869 else if (fptr
->rank
&& !shape
)
3871 gfc_error ("Expected SHAPE argument to C_F_POINTER with array "
3872 "FPTR at %L", &fptr
->where
);
3876 if (shape
&& !rank_check (shape
, 2, 1))
3879 if (shape
&& !type_check (shape
, 2, BT_INTEGER
))
3886 if (gfc_array_size (shape
, &size
)
3887 && mpz_cmp_ui (size
, fptr
->rank
) != 0)
3890 gfc_error ("SHAPE argument at %L to C_F_POINTER must have the same "
3891 "size as the RANK of FPTR", &shape
->where
);
3897 if (fptr
->ts
.type
== BT_CLASS
)
3899 gfc_error ("Polymorphic FPTR at %L to C_F_POINTER", &fptr
->where
);
3903 if (!is_c_interoperable (fptr
, &msg
, false) && fptr
->rank
)
3904 return gfc_notify_std (GFC_STD_F2008_TS
, "Noninteroperable array FPTR "
3905 "at %L to C_F_POINTER: %s", &fptr
->where
, msg
);
3912 gfc_check_c_f_procpointer (gfc_expr
*cptr
, gfc_expr
*fptr
)
3914 symbol_attribute attr
;
3916 if (cptr
->ts
.type
!= BT_DERIVED
3917 || cptr
->ts
.u
.derived
->from_intmod
!= INTMOD_ISO_C_BINDING
3918 || cptr
->ts
.u
.derived
->intmod_sym_id
!= ISOCBINDING_FUNPTR
)
3920 gfc_error ("Argument CPTR at %L to C_F_PROCPOINTER shall have the "
3921 "type TYPE(C_FUNPTR)", &cptr
->where
);
3925 if (!scalar_check (cptr
, 0))
3928 attr
= gfc_expr_attr (fptr
);
3930 if (!attr
.proc_pointer
)
3932 gfc_error ("Argument FPTR at %L to C_F_PROCPOINTER shall be a procedure "
3933 "pointer", &fptr
->where
);
3937 if (gfc_is_coindexed (fptr
))
3939 gfc_error ("Argument FPTR at %L to C_F_PROCPOINTER shall not be "
3940 "coindexed", &fptr
->where
);
3944 if (!attr
.is_bind_c
)
3945 return gfc_notify_std (GFC_STD_F2008_TS
, "Noninteroperable procedure "
3946 "pointer at %L to C_F_PROCPOINTER", &fptr
->where
);
3953 gfc_check_c_funloc (gfc_expr
*x
)
3955 symbol_attribute attr
;
3957 if (gfc_is_coindexed (x
))
3959 gfc_error ("Argument X at %L to C_FUNLOC shall not be "
3960 "coindexed", &x
->where
);
3964 attr
= gfc_expr_attr (x
);
3966 if (attr
.function
&& !attr
.proc_pointer
&& x
->expr_type
== EXPR_VARIABLE
3967 && x
->symtree
->n
.sym
== x
->symtree
->n
.sym
->result
)
3969 gfc_namespace
*ns
= gfc_current_ns
;
3971 for (ns
= gfc_current_ns
; ns
; ns
= ns
->parent
)
3972 if (x
->symtree
->n
.sym
== ns
->proc_name
)
3974 gfc_error ("Function result '%s' at %L is invalid as X argument "
3975 "to C_FUNLOC", x
->symtree
->n
.sym
->name
, &x
->where
);
3980 if (attr
.flavor
!= FL_PROCEDURE
)
3982 gfc_error ("Argument X at %L to C_FUNLOC shall be a procedure "
3983 "or a procedure pointer", &x
->where
);
3987 if (!attr
.is_bind_c
)
3988 return gfc_notify_std (GFC_STD_F2008_TS
, "Noninteroperable procedure "
3989 "at %L to C_FUNLOC", &x
->where
);
3995 gfc_check_c_loc (gfc_expr
*x
)
3997 symbol_attribute attr
;
4000 if (gfc_is_coindexed (x
))
4002 gfc_error ("Argument X at %L to C_LOC shall not be coindexed", &x
->where
);
4006 if (x
->ts
.type
== BT_CLASS
)
4008 gfc_error ("X argument at %L to C_LOC shall not be polymorphic",
4013 attr
= gfc_expr_attr (x
);
4016 && (x
->expr_type
!= EXPR_VARIABLE
|| !attr
.target
4017 || attr
.flavor
== FL_PARAMETER
))
4019 gfc_error ("Argument X at %L to C_LOC shall have either "
4020 "the POINTER or the TARGET attribute", &x
->where
);
4024 if (x
->ts
.type
== BT_CHARACTER
4025 && gfc_var_strlen (x
) == 0)
4027 gfc_error ("Argument X at %L to C_LOC shall be not be a zero-sized "
4028 "string", &x
->where
);
4032 if (!is_c_interoperable (x
, &msg
, true))
4034 if (x
->ts
.type
== BT_CLASS
)
4036 gfc_error ("Argument at %L to C_LOC shall not be polymorphic",
4042 && !gfc_notify_std (GFC_STD_F2008_TS
,
4043 "Noninteroperable array at %L as"
4044 " argument to C_LOC: %s", &x
->where
, msg
))
4047 else if (x
->rank
> 0 && gfc_notification_std (GFC_STD_F2008
))
4049 gfc_array_ref
*ar
= gfc_find_array_ref (x
);
4051 if (ar
->as
->type
!= AS_EXPLICIT
&& ar
->as
->type
!= AS_ASSUMED_SIZE
4052 && !attr
.allocatable
4053 && !gfc_notify_std (GFC_STD_F2008
,
4054 "Array of interoperable type at %L "
4055 "to C_LOC which is nonallocatable and neither "
4056 "assumed size nor explicit size", &x
->where
))
4058 else if (ar
->type
!= AR_FULL
4059 && !gfc_notify_std (GFC_STD_F2008
, "Array section at %L "
4060 "to C_LOC", &x
->where
))
4069 gfc_check_sleep_sub (gfc_expr
*seconds
)
4071 if (!type_check (seconds
, 0, BT_INTEGER
))
4074 if (!scalar_check (seconds
, 0))
4081 gfc_check_sngl (gfc_expr
*a
)
4083 if (!type_check (a
, 0, BT_REAL
))
4086 if ((a
->ts
.kind
!= gfc_default_double_kind
)
4087 && !gfc_notify_std (GFC_STD_GNU
, "non double precision "
4088 "REAL argument to %s intrinsic at %L",
4089 gfc_current_intrinsic
, &a
->where
))
4096 gfc_check_spread (gfc_expr
*source
, gfc_expr
*dim
, gfc_expr
*ncopies
)
4098 if (source
->rank
>= GFC_MAX_DIMENSIONS
)
4100 gfc_error ("'%s' argument of '%s' intrinsic at %L must be less "
4101 "than rank %d", gfc_current_intrinsic_arg
[0]->name
,
4102 gfc_current_intrinsic
, &source
->where
, GFC_MAX_DIMENSIONS
);
4110 if (!dim_check (dim
, 1, false))
4113 /* dim_rank_check() does not apply here. */
4115 && dim
->expr_type
== EXPR_CONSTANT
4116 && (mpz_cmp_ui (dim
->value
.integer
, 1) < 0
4117 || mpz_cmp_ui (dim
->value
.integer
, source
->rank
+ 1) > 0))
4119 gfc_error ("'%s' argument of '%s' intrinsic at %L is not a valid "
4120 "dimension index", gfc_current_intrinsic_arg
[1]->name
,
4121 gfc_current_intrinsic
, &dim
->where
);
4125 if (!type_check (ncopies
, 2, BT_INTEGER
))
4128 if (!scalar_check (ncopies
, 2))
4135 /* Functions for checking FGETC, FPUTC, FGET and FPUT (subroutines and
4139 gfc_check_fgetputc_sub (gfc_expr
*unit
, gfc_expr
*c
, gfc_expr
*status
)
4141 if (!type_check (unit
, 0, BT_INTEGER
))
4144 if (!scalar_check (unit
, 0))
4147 if (!type_check (c
, 1, BT_CHARACTER
))
4149 if (!kind_value_check (c
, 1, gfc_default_character_kind
))
4155 if (!type_check (status
, 2, BT_INTEGER
)
4156 || !kind_value_check (status
, 2, gfc_default_integer_kind
)
4157 || !scalar_check (status
, 2))
4165 gfc_check_fgetputc (gfc_expr
*unit
, gfc_expr
*c
)
4167 return gfc_check_fgetputc_sub (unit
, c
, NULL
);
4172 gfc_check_fgetput_sub (gfc_expr
*c
, gfc_expr
*status
)
4174 if (!type_check (c
, 0, BT_CHARACTER
))
4176 if (!kind_value_check (c
, 0, gfc_default_character_kind
))
4182 if (!type_check (status
, 1, BT_INTEGER
)
4183 || !kind_value_check (status
, 1, gfc_default_integer_kind
)
4184 || !scalar_check (status
, 1))
4192 gfc_check_fgetput (gfc_expr
*c
)
4194 return gfc_check_fgetput_sub (c
, NULL
);
4199 gfc_check_fseek_sub (gfc_expr
*unit
, gfc_expr
*offset
, gfc_expr
*whence
, gfc_expr
*status
)
4201 if (!type_check (unit
, 0, BT_INTEGER
))
4204 if (!scalar_check (unit
, 0))
4207 if (!type_check (offset
, 1, BT_INTEGER
))
4210 if (!scalar_check (offset
, 1))
4213 if (!type_check (whence
, 2, BT_INTEGER
))
4216 if (!scalar_check (whence
, 2))
4222 if (!type_check (status
, 3, BT_INTEGER
))
4225 if (!kind_value_check (status
, 3, 4))
4228 if (!scalar_check (status
, 3))
4237 gfc_check_fstat (gfc_expr
*unit
, gfc_expr
*array
)
4239 if (!type_check (unit
, 0, BT_INTEGER
))
4242 if (!scalar_check (unit
, 0))
4245 if (!type_check (array
, 1, BT_INTEGER
)
4246 || !kind_value_check (unit
, 0, gfc_default_integer_kind
))
4249 if (!array_check (array
, 1))
4257 gfc_check_fstat_sub (gfc_expr
*unit
, gfc_expr
*array
, gfc_expr
*status
)
4259 if (!type_check (unit
, 0, BT_INTEGER
))
4262 if (!scalar_check (unit
, 0))
4265 if (!type_check (array
, 1, BT_INTEGER
)
4266 || !kind_value_check (array
, 1, gfc_default_integer_kind
))
4269 if (!array_check (array
, 1))
4275 if (!type_check (status
, 2, BT_INTEGER
)
4276 || !kind_value_check (status
, 2, gfc_default_integer_kind
))
4279 if (!scalar_check (status
, 2))
4287 gfc_check_ftell (gfc_expr
*unit
)
4289 if (!type_check (unit
, 0, BT_INTEGER
))
4292 if (!scalar_check (unit
, 0))
4300 gfc_check_ftell_sub (gfc_expr
*unit
, gfc_expr
*offset
)
4302 if (!type_check (unit
, 0, BT_INTEGER
))
4305 if (!scalar_check (unit
, 0))
4308 if (!type_check (offset
, 1, BT_INTEGER
))
4311 if (!scalar_check (offset
, 1))
4319 gfc_check_stat (gfc_expr
*name
, gfc_expr
*array
)
4321 if (!type_check (name
, 0, BT_CHARACTER
))
4323 if (!kind_value_check (name
, 0, gfc_default_character_kind
))
4326 if (!type_check (array
, 1, BT_INTEGER
)
4327 || !kind_value_check (array
, 1, gfc_default_integer_kind
))
4330 if (!array_check (array
, 1))
4338 gfc_check_stat_sub (gfc_expr
*name
, gfc_expr
*array
, gfc_expr
*status
)
4340 if (!type_check (name
, 0, BT_CHARACTER
))
4342 if (!kind_value_check (name
, 0, gfc_default_character_kind
))
4345 if (!type_check (array
, 1, BT_INTEGER
)
4346 || !kind_value_check (array
, 1, gfc_default_integer_kind
))
4349 if (!array_check (array
, 1))
4355 if (!type_check (status
, 2, BT_INTEGER
)
4356 || !kind_value_check (array
, 1, gfc_default_integer_kind
))
4359 if (!scalar_check (status
, 2))
4367 gfc_check_image_index (gfc_expr
*coarray
, gfc_expr
*sub
)
4371 if (gfc_option
.coarray
== GFC_FCOARRAY_NONE
)
4373 gfc_fatal_error ("Coarrays disabled at %C, use -fcoarray= to enable");
4377 if (!coarray_check (coarray
, 0))
4382 gfc_error ("%s argument to IMAGE_INDEX must be a rank one array at %L",
4383 gfc_current_intrinsic_arg
[1]->name
, &sub
->where
);
4387 if (gfc_array_size (sub
, &nelems
))
4389 int corank
= gfc_get_corank (coarray
);
4391 if (mpz_cmp_ui (nelems
, corank
) != 0)
4393 gfc_error ("The number of array elements of the SUB argument to "
4394 "IMAGE_INDEX at %L shall be %d (corank) not %d",
4395 &sub
->where
, corank
, (int) mpz_get_si (nelems
));
4407 gfc_check_this_image (gfc_expr
*coarray
, gfc_expr
*dim
)
4409 if (gfc_option
.coarray
== GFC_FCOARRAY_NONE
)
4411 gfc_fatal_error ("Coarrays disabled at %C, use -fcoarray= to enable");
4415 if (dim
!= NULL
&& coarray
== NULL
)
4417 gfc_error ("DIM argument without ARRAY argument not allowed for THIS_IMAGE "
4418 "intrinsic at %L", &dim
->where
);
4422 if (coarray
== NULL
)
4425 if (!coarray_check (coarray
, 0))
4430 if (!dim_check (dim
, 1, false))
4433 if (!dim_corank_check (dim
, coarray
))
4440 /* Calculate the sizes for transfer, used by gfc_check_transfer and also
4441 by gfc_simplify_transfer. Return false if we cannot do so. */
4444 gfc_calculate_transfer_sizes (gfc_expr
*source
, gfc_expr
*mold
, gfc_expr
*size
,
4445 size_t *source_size
, size_t *result_size
,
4446 size_t *result_length_p
)
4448 size_t result_elt_size
;
4450 if (source
->expr_type
== EXPR_FUNCTION
)
4453 if (size
&& size
->expr_type
!= EXPR_CONSTANT
)
4456 /* Calculate the size of the source. */
4457 *source_size
= gfc_target_expr_size (source
);
4458 if (*source_size
== 0)
4461 /* Determine the size of the element. */
4462 result_elt_size
= gfc_element_size (mold
);
4463 if (result_elt_size
== 0)
4466 if (mold
->expr_type
== EXPR_ARRAY
|| mold
->rank
|| size
)
4471 result_length
= (size_t)mpz_get_ui (size
->value
.integer
);
4474 result_length
= *source_size
/ result_elt_size
;
4475 if (result_length
* result_elt_size
< *source_size
)
4479 *result_size
= result_length
* result_elt_size
;
4480 if (result_length_p
)
4481 *result_length_p
= result_length
;
4484 *result_size
= result_elt_size
;
4491 gfc_check_transfer (gfc_expr
*source
, gfc_expr
*mold
, gfc_expr
*size
)
4496 if (mold
->ts
.type
== BT_HOLLERITH
)
4498 gfc_error ("'MOLD' argument of 'TRANSFER' intrinsic at %L must not be %s",
4499 &mold
->where
, gfc_basic_typename (BT_HOLLERITH
));
4505 if (!type_check (size
, 2, BT_INTEGER
))
4508 if (!scalar_check (size
, 2))
4511 if (!nonoptional_check (size
, 2))
4515 if (!gfc_option
.warn_surprising
)
4518 /* If we can't calculate the sizes, we cannot check any more.
4519 Return true for that case. */
4521 if (!gfc_calculate_transfer_sizes (source
, mold
, size
, &source_size
,
4522 &result_size
, NULL
))
4525 if (source_size
< result_size
)
4526 gfc_warning("Intrinsic TRANSFER at %L has partly undefined result: "
4527 "source size %ld < result size %ld", &source
->where
,
4528 (long) source_size
, (long) result_size
);
4535 gfc_check_transpose (gfc_expr
*matrix
)
4537 if (!rank_check (matrix
, 0, 2))
4545 gfc_check_ubound (gfc_expr
*array
, gfc_expr
*dim
, gfc_expr
*kind
)
4547 if (!array_check (array
, 0))
4550 if (!dim_check (dim
, 1, false))
4553 if (!dim_rank_check (dim
, array
, 0))
4556 if (!kind_check (kind
, 2, BT_INTEGER
))
4558 if (kind
&& !gfc_notify_std (GFC_STD_F2003
, "'%s' intrinsic "
4559 "with KIND argument at %L",
4560 gfc_current_intrinsic
, &kind
->where
))
4568 gfc_check_ucobound (gfc_expr
*coarray
, gfc_expr
*dim
, gfc_expr
*kind
)
4570 if (gfc_option
.coarray
== GFC_FCOARRAY_NONE
)
4572 gfc_fatal_error ("Coarrays disabled at %C, use -fcoarray= to enable");
4576 if (!coarray_check (coarray
, 0))
4581 if (!dim_check (dim
, 1, false))
4584 if (!dim_corank_check (dim
, coarray
))
4588 if (!kind_check (kind
, 2, BT_INTEGER
))
4596 gfc_check_unpack (gfc_expr
*vector
, gfc_expr
*mask
, gfc_expr
*field
)
4600 if (!rank_check (vector
, 0, 1))
4603 if (!array_check (mask
, 1))
4606 if (!type_check (mask
, 1, BT_LOGICAL
))
4609 if (!same_type_check (vector
, 0, field
, 2))
4612 if (mask
->expr_type
== EXPR_ARRAY
4613 && gfc_array_size (vector
, &vector_size
))
4615 int mask_true_count
= 0;
4616 gfc_constructor
*mask_ctor
;
4617 mask_ctor
= gfc_constructor_first (mask
->value
.constructor
);
4620 if (mask_ctor
->expr
->expr_type
!= EXPR_CONSTANT
)
4622 mask_true_count
= 0;
4626 if (mask_ctor
->expr
->value
.logical
)
4629 mask_ctor
= gfc_constructor_next (mask_ctor
);
4632 if (mpz_get_si (vector_size
) < mask_true_count
)
4634 gfc_error ("'%s' argument of '%s' intrinsic at %L must "
4635 "provide at least as many elements as there "
4636 "are .TRUE. values in '%s' (%ld/%d)",
4637 gfc_current_intrinsic_arg
[0]->name
, gfc_current_intrinsic
,
4638 &vector
->where
, gfc_current_intrinsic_arg
[1]->name
,
4639 mpz_get_si (vector_size
), mask_true_count
);
4643 mpz_clear (vector_size
);
4646 if (mask
->rank
!= field
->rank
&& field
->rank
!= 0)
4648 gfc_error ("'%s' argument of '%s' intrinsic at %L must have "
4649 "the same rank as '%s' or be a scalar",
4650 gfc_current_intrinsic_arg
[2]->name
, gfc_current_intrinsic
,
4651 &field
->where
, gfc_current_intrinsic_arg
[1]->name
);
4655 if (mask
->rank
== field
->rank
)
4658 for (i
= 0; i
< field
->rank
; i
++)
4659 if (! identical_dimen_shape (mask
, i
, field
, i
))
4661 gfc_error ("'%s' and '%s' arguments of '%s' intrinsic at %L "
4662 "must have identical shape.",
4663 gfc_current_intrinsic_arg
[2]->name
,
4664 gfc_current_intrinsic_arg
[1]->name
, gfc_current_intrinsic
,
4674 gfc_check_verify (gfc_expr
*x
, gfc_expr
*y
, gfc_expr
*z
, gfc_expr
*kind
)
4676 if (!type_check (x
, 0, BT_CHARACTER
))
4679 if (!same_type_check (x
, 0, y
, 1))
4682 if (z
!= NULL
&& !type_check (z
, 2, BT_LOGICAL
))
4685 if (!kind_check (kind
, 3, BT_INTEGER
))
4687 if (kind
&& !gfc_notify_std (GFC_STD_F2003
, "'%s' intrinsic "
4688 "with KIND argument at %L",
4689 gfc_current_intrinsic
, &kind
->where
))
4697 gfc_check_trim (gfc_expr
*x
)
4699 if (!type_check (x
, 0, BT_CHARACTER
))
4702 if (!scalar_check (x
, 0))
4710 gfc_check_ttynam (gfc_expr
*unit
)
4712 if (!scalar_check (unit
, 0))
4715 if (!type_check (unit
, 0, BT_INTEGER
))
4722 /* Common check function for the half a dozen intrinsics that have a
4723 single real argument. */
4726 gfc_check_x (gfc_expr
*x
)
4728 if (!type_check (x
, 0, BT_REAL
))
4735 /************* Check functions for intrinsic subroutines *************/
4738 gfc_check_cpu_time (gfc_expr
*time
)
4740 if (!scalar_check (time
, 0))
4743 if (!type_check (time
, 0, BT_REAL
))
4746 if (!variable_check (time
, 0, false))
4754 gfc_check_date_and_time (gfc_expr
*date
, gfc_expr
*time
,
4755 gfc_expr
*zone
, gfc_expr
*values
)
4759 if (!type_check (date
, 0, BT_CHARACTER
))
4761 if (!kind_value_check (date
, 0, gfc_default_character_kind
))
4763 if (!scalar_check (date
, 0))
4765 if (!variable_check (date
, 0, false))
4771 if (!type_check (time
, 1, BT_CHARACTER
))
4773 if (!kind_value_check (time
, 1, gfc_default_character_kind
))
4775 if (!scalar_check (time
, 1))
4777 if (!variable_check (time
, 1, false))
4783 if (!type_check (zone
, 2, BT_CHARACTER
))
4785 if (!kind_value_check (zone
, 2, gfc_default_character_kind
))
4787 if (!scalar_check (zone
, 2))
4789 if (!variable_check (zone
, 2, false))
4795 if (!type_check (values
, 3, BT_INTEGER
))
4797 if (!array_check (values
, 3))
4799 if (!rank_check (values
, 3, 1))
4801 if (!variable_check (values
, 3, false))
4810 gfc_check_mvbits (gfc_expr
*from
, gfc_expr
*frompos
, gfc_expr
*len
,
4811 gfc_expr
*to
, gfc_expr
*topos
)
4813 if (!type_check (from
, 0, BT_INTEGER
))
4816 if (!type_check (frompos
, 1, BT_INTEGER
))
4819 if (!type_check (len
, 2, BT_INTEGER
))
4822 if (!same_type_check (from
, 0, to
, 3))
4825 if (!variable_check (to
, 3, false))
4828 if (!type_check (topos
, 4, BT_INTEGER
))
4831 if (!nonnegative_check ("frompos", frompos
))
4834 if (!nonnegative_check ("topos", topos
))
4837 if (!nonnegative_check ("len", len
))
4840 if (!less_than_bitsize2 ("from", from
, "frompos", frompos
, "len", len
))
4843 if (!less_than_bitsize2 ("to", to
, "topos", topos
, "len", len
))
4851 gfc_check_random_number (gfc_expr
*harvest
)
4853 if (!type_check (harvest
, 0, BT_REAL
))
4856 if (!variable_check (harvest
, 0, false))
4864 gfc_check_random_seed (gfc_expr
*size
, gfc_expr
*put
, gfc_expr
*get
)
4866 unsigned int nargs
= 0, kiss_size
;
4867 locus
*where
= NULL
;
4868 mpz_t put_size
, get_size
;
4869 bool have_gfc_real_16
; /* Try and mimic HAVE_GFC_REAL_16 in libgfortran. */
4871 have_gfc_real_16
= gfc_validate_kind (BT_REAL
, 16, true) != -1;
4873 /* Keep the number of bytes in sync with kiss_size in
4874 libgfortran/intrinsics/random.c. */
4875 kiss_size
= (have_gfc_real_16
? 48 : 32) / gfc_default_integer_kind
;
4879 if (size
->expr_type
!= EXPR_VARIABLE
4880 || !size
->symtree
->n
.sym
->attr
.optional
)
4883 if (!scalar_check (size
, 0))
4886 if (!type_check (size
, 0, BT_INTEGER
))
4889 if (!variable_check (size
, 0, false))
4892 if (!kind_value_check (size
, 0, gfc_default_integer_kind
))
4898 if (put
->expr_type
!= EXPR_VARIABLE
4899 || !put
->symtree
->n
.sym
->attr
.optional
)
4902 where
= &put
->where
;
4905 if (!array_check (put
, 1))
4908 if (!rank_check (put
, 1, 1))
4911 if (!type_check (put
, 1, BT_INTEGER
))
4914 if (!kind_value_check (put
, 1, gfc_default_integer_kind
))
4917 if (gfc_array_size (put
, &put_size
)
4918 && mpz_get_ui (put_size
) < kiss_size
)
4919 gfc_error ("Size of '%s' argument of '%s' intrinsic at %L "
4920 "too small (%i/%i)",
4921 gfc_current_intrinsic_arg
[1]->name
, gfc_current_intrinsic
,
4922 where
, (int) mpz_get_ui (put_size
), kiss_size
);
4927 if (get
->expr_type
!= EXPR_VARIABLE
4928 || !get
->symtree
->n
.sym
->attr
.optional
)
4931 where
= &get
->where
;
4934 if (!array_check (get
, 2))
4937 if (!rank_check (get
, 2, 1))
4940 if (!type_check (get
, 2, BT_INTEGER
))
4943 if (!variable_check (get
, 2, false))
4946 if (!kind_value_check (get
, 2, gfc_default_integer_kind
))
4949 if (gfc_array_size (get
, &get_size
)
4950 && mpz_get_ui (get_size
) < kiss_size
)
4951 gfc_error ("Size of '%s' argument of '%s' intrinsic at %L "
4952 "too small (%i/%i)",
4953 gfc_current_intrinsic_arg
[2]->name
, gfc_current_intrinsic
,
4954 where
, (int) mpz_get_ui (get_size
), kiss_size
);
4957 /* RANDOM_SEED may not have more than one non-optional argument. */
4959 gfc_error ("Too many arguments to %s at %L", gfc_current_intrinsic
, where
);
4966 gfc_check_second_sub (gfc_expr
*time
)
4968 if (!scalar_check (time
, 0))
4971 if (!type_check (time
, 0, BT_REAL
))
4974 if (!kind_value_check (time
, 0, 4))
4981 /* The arguments of SYSTEM_CLOCK are scalar, integer variables. Note,
4982 count, count_rate, and count_max are all optional arguments */
4985 gfc_check_system_clock (gfc_expr
*count
, gfc_expr
*count_rate
,
4986 gfc_expr
*count_max
)
4990 if (!scalar_check (count
, 0))
4993 if (!type_check (count
, 0, BT_INTEGER
))
4996 if (!variable_check (count
, 0, false))
5000 if (count_rate
!= NULL
)
5002 if (!scalar_check (count_rate
, 1))
5005 if (!type_check (count_rate
, 1, BT_INTEGER
))
5008 if (!variable_check (count_rate
, 1, false))
5012 && !same_type_check (count
, 0, count_rate
, 1))
5017 if (count_max
!= NULL
)
5019 if (!scalar_check (count_max
, 2))
5022 if (!type_check (count_max
, 2, BT_INTEGER
))
5025 if (!variable_check (count_max
, 2, false))
5029 && !same_type_check (count
, 0, count_max
, 2))
5032 if (count_rate
!= NULL
5033 && !same_type_check (count_rate
, 1, count_max
, 2))
5042 gfc_check_irand (gfc_expr
*x
)
5047 if (!scalar_check (x
, 0))
5050 if (!type_check (x
, 0, BT_INTEGER
))
5053 if (!kind_value_check (x
, 0, 4))
5061 gfc_check_alarm_sub (gfc_expr
*seconds
, gfc_expr
*handler
, gfc_expr
*status
)
5063 if (!scalar_check (seconds
, 0))
5065 if (!type_check (seconds
, 0, BT_INTEGER
))
5068 if (!int_or_proc_check (handler
, 1))
5070 if (handler
->ts
.type
== BT_INTEGER
&& !scalar_check (handler
, 1))
5076 if (!scalar_check (status
, 2))
5078 if (!type_check (status
, 2, BT_INTEGER
))
5080 if (!kind_value_check (status
, 2, gfc_default_integer_kind
))
5088 gfc_check_rand (gfc_expr
*x
)
5093 if (!scalar_check (x
, 0))
5096 if (!type_check (x
, 0, BT_INTEGER
))
5099 if (!kind_value_check (x
, 0, 4))
5107 gfc_check_srand (gfc_expr
*x
)
5109 if (!scalar_check (x
, 0))
5112 if (!type_check (x
, 0, BT_INTEGER
))
5115 if (!kind_value_check (x
, 0, 4))
5123 gfc_check_ctime_sub (gfc_expr
*time
, gfc_expr
*result
)
5125 if (!scalar_check (time
, 0))
5127 if (!type_check (time
, 0, BT_INTEGER
))
5130 if (!type_check (result
, 1, BT_CHARACTER
))
5132 if (!kind_value_check (result
, 1, gfc_default_character_kind
))
5140 gfc_check_dtime_etime (gfc_expr
*x
)
5142 if (!array_check (x
, 0))
5145 if (!rank_check (x
, 0, 1))
5148 if (!variable_check (x
, 0, false))
5151 if (!type_check (x
, 0, BT_REAL
))
5154 if (!kind_value_check (x
, 0, 4))
5162 gfc_check_dtime_etime_sub (gfc_expr
*values
, gfc_expr
*time
)
5164 if (!array_check (values
, 0))
5167 if (!rank_check (values
, 0, 1))
5170 if (!variable_check (values
, 0, false))
5173 if (!type_check (values
, 0, BT_REAL
))
5176 if (!kind_value_check (values
, 0, 4))
5179 if (!scalar_check (time
, 1))
5182 if (!type_check (time
, 1, BT_REAL
))
5185 if (!kind_value_check (time
, 1, 4))
5193 gfc_check_fdate_sub (gfc_expr
*date
)
5195 if (!type_check (date
, 0, BT_CHARACTER
))
5197 if (!kind_value_check (date
, 0, gfc_default_character_kind
))
5205 gfc_check_gerror (gfc_expr
*msg
)
5207 if (!type_check (msg
, 0, BT_CHARACTER
))
5209 if (!kind_value_check (msg
, 0, gfc_default_character_kind
))
5217 gfc_check_getcwd_sub (gfc_expr
*cwd
, gfc_expr
*status
)
5219 if (!type_check (cwd
, 0, BT_CHARACTER
))
5221 if (!kind_value_check (cwd
, 0, gfc_default_character_kind
))
5227 if (!scalar_check (status
, 1))
5230 if (!type_check (status
, 1, BT_INTEGER
))
5238 gfc_check_getarg (gfc_expr
*pos
, gfc_expr
*value
)
5240 if (!type_check (pos
, 0, BT_INTEGER
))
5243 if (pos
->ts
.kind
> gfc_default_integer_kind
)
5245 gfc_error ("'%s' argument of '%s' intrinsic at %L must be of a kind "
5246 "not wider than the default kind (%d)",
5247 gfc_current_intrinsic_arg
[0]->name
, gfc_current_intrinsic
,
5248 &pos
->where
, gfc_default_integer_kind
);
5252 if (!type_check (value
, 1, BT_CHARACTER
))
5254 if (!kind_value_check (value
, 1, gfc_default_character_kind
))
5262 gfc_check_getlog (gfc_expr
*msg
)
5264 if (!type_check (msg
, 0, BT_CHARACTER
))
5266 if (!kind_value_check (msg
, 0, gfc_default_character_kind
))
5274 gfc_check_exit (gfc_expr
*status
)
5279 if (!type_check (status
, 0, BT_INTEGER
))
5282 if (!scalar_check (status
, 0))
5290 gfc_check_flush (gfc_expr
*unit
)
5295 if (!type_check (unit
, 0, BT_INTEGER
))
5298 if (!scalar_check (unit
, 0))
5306 gfc_check_free (gfc_expr
*i
)
5308 if (!type_check (i
, 0, BT_INTEGER
))
5311 if (!scalar_check (i
, 0))
5319 gfc_check_hostnm (gfc_expr
*name
)
5321 if (!type_check (name
, 0, BT_CHARACTER
))
5323 if (!kind_value_check (name
, 0, gfc_default_character_kind
))
5331 gfc_check_hostnm_sub (gfc_expr
*name
, gfc_expr
*status
)
5333 if (!type_check (name
, 0, BT_CHARACTER
))
5335 if (!kind_value_check (name
, 0, gfc_default_character_kind
))
5341 if (!scalar_check (status
, 1))
5344 if (!type_check (status
, 1, BT_INTEGER
))
5352 gfc_check_itime_idate (gfc_expr
*values
)
5354 if (!array_check (values
, 0))
5357 if (!rank_check (values
, 0, 1))
5360 if (!variable_check (values
, 0, false))
5363 if (!type_check (values
, 0, BT_INTEGER
))
5366 if (!kind_value_check (values
, 0, gfc_default_integer_kind
))
5374 gfc_check_ltime_gmtime (gfc_expr
*time
, gfc_expr
*values
)
5376 if (!type_check (time
, 0, BT_INTEGER
))
5379 if (!kind_value_check (time
, 0, gfc_default_integer_kind
))
5382 if (!scalar_check (time
, 0))
5385 if (!array_check (values
, 1))
5388 if (!rank_check (values
, 1, 1))
5391 if (!variable_check (values
, 1, false))
5394 if (!type_check (values
, 1, BT_INTEGER
))
5397 if (!kind_value_check (values
, 1, gfc_default_integer_kind
))
5405 gfc_check_ttynam_sub (gfc_expr
*unit
, gfc_expr
*name
)
5407 if (!scalar_check (unit
, 0))
5410 if (!type_check (unit
, 0, BT_INTEGER
))
5413 if (!type_check (name
, 1, BT_CHARACTER
))
5415 if (!kind_value_check (name
, 1, gfc_default_character_kind
))
5423 gfc_check_isatty (gfc_expr
*unit
)
5428 if (!type_check (unit
, 0, BT_INTEGER
))
5431 if (!scalar_check (unit
, 0))
5439 gfc_check_isnan (gfc_expr
*x
)
5441 if (!type_check (x
, 0, BT_REAL
))
5449 gfc_check_perror (gfc_expr
*string
)
5451 if (!type_check (string
, 0, BT_CHARACTER
))
5453 if (!kind_value_check (string
, 0, gfc_default_character_kind
))
5461 gfc_check_umask (gfc_expr
*mask
)
5463 if (!type_check (mask
, 0, BT_INTEGER
))
5466 if (!scalar_check (mask
, 0))
5474 gfc_check_umask_sub (gfc_expr
*mask
, gfc_expr
*old
)
5476 if (!type_check (mask
, 0, BT_INTEGER
))
5479 if (!scalar_check (mask
, 0))
5485 if (!scalar_check (old
, 1))
5488 if (!type_check (old
, 1, BT_INTEGER
))
5496 gfc_check_unlink (gfc_expr
*name
)
5498 if (!type_check (name
, 0, BT_CHARACTER
))
5500 if (!kind_value_check (name
, 0, gfc_default_character_kind
))
5508 gfc_check_unlink_sub (gfc_expr
*name
, gfc_expr
*status
)
5510 if (!type_check (name
, 0, BT_CHARACTER
))
5512 if (!kind_value_check (name
, 0, gfc_default_character_kind
))
5518 if (!scalar_check (status
, 1))
5521 if (!type_check (status
, 1, BT_INTEGER
))
5529 gfc_check_signal (gfc_expr
*number
, gfc_expr
*handler
)
5531 if (!scalar_check (number
, 0))
5533 if (!type_check (number
, 0, BT_INTEGER
))
5536 if (!int_or_proc_check (handler
, 1))
5538 if (handler
->ts
.type
== BT_INTEGER
&& !scalar_check (handler
, 1))
5546 gfc_check_signal_sub (gfc_expr
*number
, gfc_expr
*handler
, gfc_expr
*status
)
5548 if (!scalar_check (number
, 0))
5550 if (!type_check (number
, 0, BT_INTEGER
))
5553 if (!int_or_proc_check (handler
, 1))
5555 if (handler
->ts
.type
== BT_INTEGER
&& !scalar_check (handler
, 1))
5561 if (!type_check (status
, 2, BT_INTEGER
))
5563 if (!scalar_check (status
, 2))
5571 gfc_check_system_sub (gfc_expr
*cmd
, gfc_expr
*status
)
5573 if (!type_check (cmd
, 0, BT_CHARACTER
))
5575 if (!kind_value_check (cmd
, 0, gfc_default_character_kind
))
5578 if (!scalar_check (status
, 1))
5581 if (!type_check (status
, 1, BT_INTEGER
))
5584 if (!kind_value_check (status
, 1, gfc_default_integer_kind
))
5591 /* This is used for the GNU intrinsics AND, OR and XOR. */
5593 gfc_check_and (gfc_expr
*i
, gfc_expr
*j
)
5595 if (i
->ts
.type
!= BT_INTEGER
&& i
->ts
.type
!= BT_LOGICAL
)
5597 gfc_error ("'%s' argument of '%s' intrinsic at %L must be INTEGER "
5598 "or LOGICAL", gfc_current_intrinsic_arg
[0]->name
,
5599 gfc_current_intrinsic
, &i
->where
);
5603 if (j
->ts
.type
!= BT_INTEGER
&& j
->ts
.type
!= BT_LOGICAL
)
5605 gfc_error ("'%s' argument of '%s' intrinsic at %L must be INTEGER "
5606 "or LOGICAL", gfc_current_intrinsic_arg
[1]->name
,
5607 gfc_current_intrinsic
, &j
->where
);
5611 if (i
->ts
.type
!= j
->ts
.type
)
5613 gfc_error ("'%s' and '%s' arguments of '%s' intrinsic at %L must "
5614 "have the same type", gfc_current_intrinsic_arg
[0]->name
,
5615 gfc_current_intrinsic_arg
[1]->name
, gfc_current_intrinsic
,
5620 if (!scalar_check (i
, 0))
5623 if (!scalar_check (j
, 1))
5631 gfc_check_storage_size (gfc_expr
*a
, gfc_expr
*kind
)
5633 if (a
->ts
.type
== BT_ASSUMED
)
5635 gfc_error ("'%s' argument of '%s' intrinsic at %L shall not be TYPE(*)",
5636 gfc_current_intrinsic_arg
[0]->name
, gfc_current_intrinsic
,
5641 if (a
->ts
.type
== BT_PROCEDURE
)
5643 gfc_error ("'%s' argument of '%s' intrinsic at %L shall not be a "
5644 "procedure", gfc_current_intrinsic_arg
[0]->name
,
5645 gfc_current_intrinsic
, &a
->where
);
5652 if (!type_check (kind
, 1, BT_INTEGER
))
5655 if (!scalar_check (kind
, 1))
5658 if (kind
->expr_type
!= EXPR_CONSTANT
)
5660 gfc_error ("'%s' argument of '%s' intrinsic at %L must be a constant",
5661 gfc_current_intrinsic_arg
[1]->name
, gfc_current_intrinsic
,