2 Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
3 Free Software Foundation, Inc.
4 Contributed by Andy Vaught & Katherine Holcomb
6 This file is part of GCC.
8 GCC is free software; you can redistribute it and/or modify it under
9 the terms of the GNU General Public License as published by the Free
10 Software Foundation; either version 3, or (at your option) any later
13 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING3. If not see
20 <http://www.gnu.org/licenses/>. */
23 /* These functions check to see if an argument list is compatible with
24 a particular intrinsic function or subroutine. Presence of
25 required arguments has already been established, the argument list
26 has been sorted into the right order and has NULL arguments in the
27 correct places for missing optional arguments. */
33 #include "intrinsic.h"
34 #include "constructor.h"
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_VARIABLE
)
81 && e
->symtree
->n
.sym
->ts
.type
== BT_UNKNOWN
82 && gfc_set_default_type (e
->symtree
->n
.sym
, 0,
83 e
->symtree
->n
.sym
->ns
) == SUCCESS
84 && gfc_numeric_ts (&e
->symtree
->n
.sym
->ts
))
86 e
->ts
= e
->symtree
->n
.sym
->ts
;
90 gfc_error ("'%s' argument of '%s' intrinsic at %L must be a numeric type",
91 gfc_current_intrinsic_arg
[n
]->name
, gfc_current_intrinsic
,
98 /* Check that an expression is integer or real. */
101 int_or_real_check (gfc_expr
*e
, int n
)
103 if (e
->ts
.type
!= BT_INTEGER
&& e
->ts
.type
!= BT_REAL
)
105 gfc_error ("'%s' argument of '%s' intrinsic at %L must be INTEGER "
106 "or REAL", gfc_current_intrinsic_arg
[n
]->name
,
107 gfc_current_intrinsic
, &e
->where
);
115 /* Check that an expression is real or complex. */
118 real_or_complex_check (gfc_expr
*e
, int n
)
120 if (e
->ts
.type
!= BT_REAL
&& e
->ts
.type
!= BT_COMPLEX
)
122 gfc_error ("'%s' argument of '%s' intrinsic at %L must be REAL "
123 "or COMPLEX", gfc_current_intrinsic_arg
[n
]->name
,
124 gfc_current_intrinsic
, &e
->where
);
132 /* Check that an expression is INTEGER or PROCEDURE. */
135 int_or_proc_check (gfc_expr
*e
, int n
)
137 if (e
->ts
.type
!= BT_INTEGER
&& e
->ts
.type
!= BT_PROCEDURE
)
139 gfc_error ("'%s' argument of '%s' intrinsic at %L must be INTEGER "
140 "or PROCEDURE", gfc_current_intrinsic_arg
[n
]->name
,
141 gfc_current_intrinsic
, &e
->where
);
149 /* Check that the expression is an optional constant integer
150 and that it specifies a valid kind for that type. */
153 kind_check (gfc_expr
*k
, int n
, bt type
)
160 if (type_check (k
, n
, BT_INTEGER
) == FAILURE
)
163 if (scalar_check (k
, n
) == FAILURE
)
166 if (k
->expr_type
!= EXPR_CONSTANT
)
168 gfc_error ("'%s' argument of '%s' intrinsic at %L must be a constant",
169 gfc_current_intrinsic_arg
[n
]->name
, gfc_current_intrinsic
,
174 if (gfc_extract_int (k
, &kind
) != NULL
175 || gfc_validate_kind (type
, kind
, true) < 0)
177 gfc_error ("Invalid kind for %s at %L", gfc_basic_typename (type
),
186 /* Make sure the expression is a double precision real. */
189 double_check (gfc_expr
*d
, int n
)
191 if (type_check (d
, n
, BT_REAL
) == FAILURE
)
194 if (d
->ts
.kind
!= gfc_default_double_kind
)
196 gfc_error ("'%s' argument of '%s' intrinsic at %L must be double "
197 "precision", gfc_current_intrinsic_arg
[n
]->name
,
198 gfc_current_intrinsic
, &d
->where
);
207 coarray_check (gfc_expr
*e
, int n
)
209 if (e
->ts
.type
== BT_CLASS
&& gfc_expr_attr (e
).class_ok
210 && CLASS_DATA (e
)->attr
.codimension
211 && CLASS_DATA (e
)->as
->corank
)
213 gfc_add_class_array_ref (e
);
217 if (!gfc_is_coarray (e
))
219 gfc_error ("Expected coarray variable as '%s' argument to the %s "
220 "intrinsic at %L", gfc_current_intrinsic_arg
[n
]->name
,
221 gfc_current_intrinsic
, &e
->where
);
229 /* Make sure the expression is a logical array. */
232 logical_array_check (gfc_expr
*array
, int n
)
234 if (array
->ts
.type
!= BT_LOGICAL
|| array
->rank
== 0)
236 gfc_error ("'%s' argument of '%s' intrinsic at %L must be a logical "
237 "array", gfc_current_intrinsic_arg
[n
]->name
,
238 gfc_current_intrinsic
, &array
->where
);
246 /* Make sure an expression is an array. */
249 array_check (gfc_expr
*e
, int n
)
251 if (e
->ts
.type
== BT_CLASS
&& gfc_expr_attr (e
).class_ok
252 && CLASS_DATA (e
)->attr
.dimension
253 && CLASS_DATA (e
)->as
->rank
)
255 gfc_add_class_array_ref (e
);
262 gfc_error ("'%s' argument of '%s' intrinsic at %L must be an array",
263 gfc_current_intrinsic_arg
[n
]->name
, gfc_current_intrinsic
,
270 /* If expr is a constant, then check to ensure that it is greater than
274 nonnegative_check (const char *arg
, gfc_expr
*expr
)
278 if (expr
->expr_type
== EXPR_CONSTANT
)
280 gfc_extract_int (expr
, &i
);
283 gfc_error ("'%s' at %L must be nonnegative", arg
, &expr
->where
);
292 /* If expr2 is constant, then check that the value is less than
293 (less than or equal to, if 'or_equal' is true) bit_size(expr1). */
296 less_than_bitsize1 (const char *arg1
, gfc_expr
*expr1
, const char *arg2
,
297 gfc_expr
*expr2
, bool or_equal
)
301 if (expr2
->expr_type
== EXPR_CONSTANT
)
303 gfc_extract_int (expr2
, &i2
);
304 i3
= gfc_validate_kind (BT_INTEGER
, expr1
->ts
.kind
, false);
306 /* For ISHFT[C], check that |shift| <= bit_size(i). */
312 if (i2
> gfc_integer_kinds
[i3
].bit_size
)
314 gfc_error ("The absolute value of SHIFT at %L must be less "
315 "than or equal to BIT_SIZE('%s')",
316 &expr2
->where
, arg1
);
323 if (i2
> gfc_integer_kinds
[i3
].bit_size
)
325 gfc_error ("'%s' at %L must be less than "
326 "or equal to BIT_SIZE('%s')",
327 arg2
, &expr2
->where
, arg1
);
333 if (i2
>= gfc_integer_kinds
[i3
].bit_size
)
335 gfc_error ("'%s' at %L must be less than BIT_SIZE('%s')",
336 arg2
, &expr2
->where
, arg1
);
346 /* If expr is constant, then check that the value is less than or equal
347 to the bit_size of the kind k. */
350 less_than_bitsizekind (const char *arg
, gfc_expr
*expr
, int k
)
354 if (expr
->expr_type
!= EXPR_CONSTANT
)
357 i
= gfc_validate_kind (BT_INTEGER
, k
, false);
358 gfc_extract_int (expr
, &val
);
360 if (val
> gfc_integer_kinds
[i
].bit_size
)
362 gfc_error ("'%s' at %L must be less than or equal to the BIT_SIZE of "
363 "INTEGER(KIND=%d)", arg
, &expr
->where
, k
);
371 /* If expr2 and expr3 are constants, then check that the value is less than
372 or equal to bit_size(expr1). */
375 less_than_bitsize2 (const char *arg1
, gfc_expr
*expr1
, const char *arg2
,
376 gfc_expr
*expr2
, const char *arg3
, gfc_expr
*expr3
)
380 if (expr2
->expr_type
== EXPR_CONSTANT
&& expr3
->expr_type
== EXPR_CONSTANT
)
382 gfc_extract_int (expr2
, &i2
);
383 gfc_extract_int (expr3
, &i3
);
385 i3
= gfc_validate_kind (BT_INTEGER
, expr1
->ts
.kind
, false);
386 if (i2
> gfc_integer_kinds
[i3
].bit_size
)
388 gfc_error ("'%s + %s' at %L must be less than or equal "
390 arg2
, arg3
, &expr2
->where
, arg1
);
398 /* Make sure two expressions have the same type. */
401 same_type_check (gfc_expr
*e
, int n
, gfc_expr
*f
, int m
)
403 if (gfc_compare_types (&e
->ts
, &f
->ts
))
406 gfc_error ("'%s' argument of '%s' intrinsic at %L must be the same type "
407 "and kind as '%s'", gfc_current_intrinsic_arg
[m
]->name
,
408 gfc_current_intrinsic
, &f
->where
,
409 gfc_current_intrinsic_arg
[n
]->name
);
415 /* Make sure that an expression has a certain (nonzero) rank. */
418 rank_check (gfc_expr
*e
, int n
, int rank
)
423 gfc_error ("'%s' argument of '%s' intrinsic at %L must be of rank %d",
424 gfc_current_intrinsic_arg
[n
]->name
, gfc_current_intrinsic
,
431 /* Make sure a variable expression is not an optional dummy argument. */
434 nonoptional_check (gfc_expr
*e
, int n
)
436 if (e
->expr_type
== EXPR_VARIABLE
&& e
->symtree
->n
.sym
->attr
.optional
)
438 gfc_error ("'%s' argument of '%s' intrinsic at %L must not be OPTIONAL",
439 gfc_current_intrinsic_arg
[n
]->name
, gfc_current_intrinsic
,
443 /* TODO: Recursive check on nonoptional variables? */
449 /* Check for ALLOCATABLE attribute. */
452 allocatable_check (gfc_expr
*e
, int n
)
454 symbol_attribute attr
;
456 attr
= gfc_variable_attr (e
, NULL
);
457 if (!attr
.allocatable
)
459 gfc_error ("'%s' argument of '%s' intrinsic at %L must be ALLOCATABLE",
460 gfc_current_intrinsic_arg
[n
]->name
, gfc_current_intrinsic
,
469 /* Check that an expression has a particular kind. */
472 kind_value_check (gfc_expr
*e
, int n
, int k
)
477 gfc_error ("'%s' argument of '%s' intrinsic at %L must be of kind %d",
478 gfc_current_intrinsic_arg
[n
]->name
, gfc_current_intrinsic
,
485 /* Make sure an expression is a variable. */
488 variable_check (gfc_expr
*e
, int n
, bool allow_proc
)
490 if (e
->expr_type
== EXPR_VARIABLE
491 && e
->symtree
->n
.sym
->attr
.intent
== INTENT_IN
492 && (gfc_current_intrinsic_arg
[n
]->intent
== INTENT_OUT
493 || gfc_current_intrinsic_arg
[n
]->intent
== INTENT_INOUT
))
496 bool pointer
= e
->symtree
->n
.sym
->ts
.type
== BT_CLASS
497 && CLASS_DATA (e
->symtree
->n
.sym
)
498 ? CLASS_DATA (e
->symtree
->n
.sym
)->attr
.class_pointer
499 : e
->symtree
->n
.sym
->attr
.pointer
;
501 for (ref
= e
->ref
; ref
; ref
= ref
->next
)
503 if (pointer
&& ref
->type
== REF_COMPONENT
)
505 if (ref
->type
== REF_COMPONENT
506 && ((ref
->u
.c
.component
->ts
.type
== BT_CLASS
507 && CLASS_DATA (ref
->u
.c
.component
)->attr
.class_pointer
)
508 || (ref
->u
.c
.component
->ts
.type
!= BT_CLASS
509 && ref
->u
.c
.component
->attr
.pointer
)))
515 gfc_error ("'%s' argument of '%s' intrinsic at %L cannot be "
516 "INTENT(IN)", gfc_current_intrinsic_arg
[n
]->name
,
517 gfc_current_intrinsic
, &e
->where
);
522 if (e
->expr_type
== EXPR_VARIABLE
523 && e
->symtree
->n
.sym
->attr
.flavor
!= FL_PARAMETER
525 || !e
->symtree
->n
.sym
->attr
.function
526 || (e
->symtree
->n
.sym
== e
->symtree
->n
.sym
->result
527 && (e
->symtree
->n
.sym
== gfc_current_ns
->proc_name
528 || (gfc_current_ns
->parent
530 == gfc_current_ns
->parent
->proc_name
)))))
533 gfc_error ("'%s' argument of '%s' intrinsic at %L must be a variable",
534 gfc_current_intrinsic_arg
[n
]->name
, gfc_current_intrinsic
, &e
->where
);
540 /* Check the common DIM parameter for correctness. */
543 dim_check (gfc_expr
*dim
, int n
, bool optional
)
548 if (type_check (dim
, n
, BT_INTEGER
) == FAILURE
)
551 if (scalar_check (dim
, n
) == FAILURE
)
554 if (!optional
&& nonoptional_check (dim
, n
) == FAILURE
)
561 /* If a coarray DIM parameter is a constant, make sure that it is greater than
562 zero and less than or equal to the corank of the given array. */
565 dim_corank_check (gfc_expr
*dim
, gfc_expr
*array
)
569 gcc_assert (array
->expr_type
== EXPR_VARIABLE
);
571 if (dim
->expr_type
!= EXPR_CONSTANT
)
574 if (array
->ts
.type
== BT_CLASS
)
577 corank
= gfc_get_corank (array
);
579 if (mpz_cmp_ui (dim
->value
.integer
, 1) < 0
580 || mpz_cmp_ui (dim
->value
.integer
, corank
) > 0)
582 gfc_error ("'dim' argument of '%s' intrinsic at %L is not a valid "
583 "codimension index", gfc_current_intrinsic
, &dim
->where
);
592 /* If a DIM parameter is a constant, make sure that it is greater than
593 zero and less than or equal to the rank of the given array. If
594 allow_assumed is zero then dim must be less than the rank of the array
595 for assumed size arrays. */
598 dim_rank_check (gfc_expr
*dim
, gfc_expr
*array
, int allow_assumed
)
606 if (dim
->expr_type
!= EXPR_CONSTANT
)
609 if (array
->ts
.type
== BT_CLASS
)
612 if (array
->expr_type
== EXPR_FUNCTION
&& array
->value
.function
.isym
613 && array
->value
.function
.isym
->id
== GFC_ISYM_SPREAD
)
614 rank
= array
->rank
+ 1;
618 if (array
->expr_type
== EXPR_VARIABLE
)
620 ar
= gfc_find_array_ref (array
);
621 if (ar
->as
->type
== AS_ASSUMED_SIZE
623 && ar
->type
!= AR_ELEMENT
624 && ar
->type
!= AR_SECTION
)
628 if (mpz_cmp_ui (dim
->value
.integer
, 1) < 0
629 || mpz_cmp_ui (dim
->value
.integer
, rank
) > 0)
631 gfc_error ("'dim' argument of '%s' intrinsic at %L is not a valid "
632 "dimension index", gfc_current_intrinsic
, &dim
->where
);
641 /* Compare the size of a along dimension ai with the size of b along
642 dimension bi, returning 0 if they are known not to be identical,
643 and 1 if they are identical, or if this cannot be determined. */
646 identical_dimen_shape (gfc_expr
*a
, int ai
, gfc_expr
*b
, int bi
)
648 mpz_t a_size
, b_size
;
651 gcc_assert (a
->rank
> ai
);
652 gcc_assert (b
->rank
> bi
);
656 if (gfc_array_dimen_size (a
, ai
, &a_size
) == SUCCESS
)
658 if (gfc_array_dimen_size (b
, bi
, &b_size
) == SUCCESS
)
660 if (mpz_cmp (a_size
, b_size
) != 0)
670 /* Calculate the length of a character variable, including substrings.
671 Strip away parentheses if necessary. Return -1 if no length could
675 gfc_var_strlen (const gfc_expr
*a
)
679 while (a
->expr_type
== EXPR_OP
&& a
->value
.op
.op
== INTRINSIC_PARENTHESES
)
682 for (ra
= a
->ref
; ra
!= NULL
&& ra
->type
!= REF_SUBSTRING
; ra
= ra
->next
)
689 if (ra
->u
.ss
.start
->expr_type
== EXPR_CONSTANT
690 && ra
->u
.ss
.end
->expr_type
== EXPR_CONSTANT
)
692 start_a
= mpz_get_si (ra
->u
.ss
.start
->value
.integer
);
693 end_a
= mpz_get_si (ra
->u
.ss
.end
->value
.integer
);
694 return end_a
- start_a
+ 1;
696 else if (gfc_dep_compare_expr (ra
->u
.ss
.start
, ra
->u
.ss
.end
) == 0)
702 if (a
->ts
.u
.cl
&& a
->ts
.u
.cl
->length
703 && a
->ts
.u
.cl
->length
->expr_type
== EXPR_CONSTANT
)
704 return mpz_get_si (a
->ts
.u
.cl
->length
->value
.integer
);
705 else if (a
->expr_type
== EXPR_CONSTANT
706 && (a
->ts
.u
.cl
== NULL
|| a
->ts
.u
.cl
->length
== NULL
))
707 return a
->value
.character
.length
;
713 /* Check whether two character expressions have the same length;
714 returns SUCCESS if they have or if the length cannot be determined,
715 otherwise return FAILURE and raise a gfc_error. */
718 gfc_check_same_strlen (const gfc_expr
*a
, const gfc_expr
*b
, const char *name
)
722 len_a
= gfc_var_strlen(a
);
723 len_b
= gfc_var_strlen(b
);
725 if (len_a
== -1 || len_b
== -1 || len_a
== len_b
)
729 gfc_error ("Unequal character lengths (%ld/%ld) in %s at %L",
730 len_a
, len_b
, name
, &a
->where
);
736 /***** Check functions *****/
738 /* Check subroutine suitable for intrinsics taking a real argument and
739 a kind argument for the result. */
742 check_a_kind (gfc_expr
*a
, gfc_expr
*kind
, bt type
)
744 if (type_check (a
, 0, BT_REAL
) == FAILURE
)
746 if (kind_check (kind
, 1, type
) == FAILURE
)
753 /* Check subroutine suitable for ceiling, floor and nint. */
756 gfc_check_a_ikind (gfc_expr
*a
, gfc_expr
*kind
)
758 return check_a_kind (a
, kind
, BT_INTEGER
);
762 /* Check subroutine suitable for aint, anint. */
765 gfc_check_a_xkind (gfc_expr
*a
, gfc_expr
*kind
)
767 return check_a_kind (a
, kind
, BT_REAL
);
772 gfc_check_abs (gfc_expr
*a
)
774 if (numeric_check (a
, 0) == FAILURE
)
782 gfc_check_achar (gfc_expr
*a
, gfc_expr
*kind
)
784 if (type_check (a
, 0, BT_INTEGER
) == FAILURE
)
786 if (kind_check (kind
, 1, BT_CHARACTER
) == FAILURE
)
794 gfc_check_access_func (gfc_expr
*name
, gfc_expr
*mode
)
796 if (type_check (name
, 0, BT_CHARACTER
) == FAILURE
797 || scalar_check (name
, 0) == FAILURE
)
799 if (kind_value_check (name
, 0, gfc_default_character_kind
) == FAILURE
)
802 if (type_check (mode
, 1, BT_CHARACTER
) == FAILURE
803 || scalar_check (mode
, 1) == FAILURE
)
805 if (kind_value_check (mode
, 1, gfc_default_character_kind
) == FAILURE
)
813 gfc_check_all_any (gfc_expr
*mask
, gfc_expr
*dim
)
815 if (logical_array_check (mask
, 0) == FAILURE
)
818 if (dim_check (dim
, 1, false) == FAILURE
)
821 if (dim_rank_check (dim
, mask
, 0) == FAILURE
)
829 gfc_check_allocated (gfc_expr
*array
)
831 if (variable_check (array
, 0, false) == FAILURE
)
833 if (allocatable_check (array
, 0) == FAILURE
)
840 /* Common check function where the first argument must be real or
841 integer and the second argument must be the same as the first. */
844 gfc_check_a_p (gfc_expr
*a
, gfc_expr
*p
)
846 if (int_or_real_check (a
, 0) == FAILURE
)
849 if (a
->ts
.type
!= p
->ts
.type
)
851 gfc_error ("'%s' and '%s' arguments of '%s' intrinsic at %L must "
852 "have the same type", gfc_current_intrinsic_arg
[0]->name
,
853 gfc_current_intrinsic_arg
[1]->name
, gfc_current_intrinsic
,
858 if (a
->ts
.kind
!= p
->ts
.kind
)
860 if (gfc_notify_std (GFC_STD_GNU
, "Extension: Different type kinds at %L",
861 &p
->where
) == FAILURE
)
870 gfc_check_x_yd (gfc_expr
*x
, gfc_expr
*y
)
872 if (double_check (x
, 0) == FAILURE
|| double_check (y
, 1) == FAILURE
)
880 gfc_check_associated (gfc_expr
*pointer
, gfc_expr
*target
)
882 symbol_attribute attr1
, attr2
;
887 where
= &pointer
->where
;
889 if (pointer
->expr_type
== EXPR_VARIABLE
|| pointer
->expr_type
== EXPR_FUNCTION
)
890 attr1
= gfc_expr_attr (pointer
);
891 else if (pointer
->expr_type
== EXPR_NULL
)
894 gcc_assert (0); /* Pointer must be a variable or a function. */
896 if (!attr1
.pointer
&& !attr1
.proc_pointer
)
898 gfc_error ("'%s' argument of '%s' intrinsic at %L must be a POINTER",
899 gfc_current_intrinsic_arg
[0]->name
, gfc_current_intrinsic
,
905 if (attr1
.pointer
&& gfc_is_coindexed (pointer
))
907 gfc_error ("'%s' argument of '%s' intrinsic at %L shall not be "
908 "conindexed", gfc_current_intrinsic_arg
[0]->name
,
909 gfc_current_intrinsic
, &pointer
->where
);
913 /* Target argument is optional. */
917 where
= &target
->where
;
918 if (target
->expr_type
== EXPR_NULL
)
921 if (target
->expr_type
== EXPR_VARIABLE
|| target
->expr_type
== EXPR_FUNCTION
)
922 attr2
= gfc_expr_attr (target
);
925 gfc_error ("'%s' argument of '%s' intrinsic at %L must be a pointer "
926 "or target VARIABLE or FUNCTION",
927 gfc_current_intrinsic_arg
[1]->name
, gfc_current_intrinsic
,
932 if (attr1
.pointer
&& !attr2
.pointer
&& !attr2
.target
)
934 gfc_error ("'%s' argument of '%s' intrinsic at %L must be a POINTER "
935 "or a TARGET", gfc_current_intrinsic_arg
[1]->name
,
936 gfc_current_intrinsic
, &target
->where
);
941 if (attr1
.pointer
&& gfc_is_coindexed (target
))
943 gfc_error ("'%s' argument of '%s' intrinsic at %L shall not be "
944 "conindexed", gfc_current_intrinsic_arg
[1]->name
,
945 gfc_current_intrinsic
, &target
->where
);
950 if (same_type_check (pointer
, 0, target
, 1) == FAILURE
)
952 if (rank_check (target
, 0, pointer
->rank
) == FAILURE
)
954 if (target
->rank
> 0)
956 for (i
= 0; i
< target
->rank
; i
++)
957 if (target
->ref
->u
.ar
.dimen_type
[i
] == DIMEN_VECTOR
)
959 gfc_error ("Array section with a vector subscript at %L shall not "
960 "be the target of a pointer",
970 gfc_error ("NULL pointer at %L is not permitted as actual argument "
971 "of '%s' intrinsic function", where
, gfc_current_intrinsic
);
978 gfc_check_atan_2 (gfc_expr
*y
, gfc_expr
*x
)
980 /* gfc_notify_std would be a waste of time as the return value
981 is seemingly used only for the generic resolution. The error
982 will be: Too many arguments. */
983 if ((gfc_option
.allow_std
& GFC_STD_F2008
) == 0)
986 return gfc_check_atan2 (y
, x
);
991 gfc_check_atan2 (gfc_expr
*y
, gfc_expr
*x
)
993 if (type_check (y
, 0, BT_REAL
) == FAILURE
)
995 if (same_type_check (y
, 0, x
, 1) == FAILURE
)
1003 gfc_check_atomic (gfc_expr
*atom
, gfc_expr
*value
)
1005 if (!(atom
->ts
.type
== BT_INTEGER
&& atom
->ts
.kind
== gfc_atomic_int_kind
)
1006 && !(atom
->ts
.type
== BT_LOGICAL
1007 && atom
->ts
.kind
== gfc_atomic_logical_kind
))
1009 gfc_error ("ATOM argument at %L to intrinsic function %s shall be an "
1010 "integer of ATOMIC_INT_KIND or a logical of "
1011 "ATOMIC_LOGICAL_KIND", &atom
->where
, gfc_current_intrinsic
);
1015 if (!gfc_expr_attr (atom
).codimension
)
1017 gfc_error ("ATOM argument at %L of the %s intrinsic function shall be a "
1018 "coarray or coindexed", &atom
->where
, gfc_current_intrinsic
);
1022 if (atom
->ts
.type
!= value
->ts
.type
)
1024 gfc_error ("ATOM and VALUE argument of the %s intrinsic function shall "
1025 "have the same type at %L", gfc_current_intrinsic
,
1035 gfc_check_atomic_def (gfc_expr
*atom
, gfc_expr
*value
)
1037 if (scalar_check (atom
, 0) == FAILURE
|| scalar_check (value
, 1) == FAILURE
)
1040 if (gfc_check_vardef_context (atom
, false, false, NULL
) == FAILURE
)
1042 gfc_error ("ATOM argument of the %s intrinsic function at %L shall be "
1043 "definable", gfc_current_intrinsic
, &atom
->where
);
1047 return gfc_check_atomic (atom
, value
);
1052 gfc_check_atomic_ref (gfc_expr
*value
, gfc_expr
*atom
)
1054 if (scalar_check (value
, 0) == FAILURE
|| scalar_check (atom
, 1) == FAILURE
)
1057 if (gfc_check_vardef_context (value
, false, false, NULL
) == FAILURE
)
1059 gfc_error ("VALUE argument of the %s intrinsic function at %L shall be "
1060 "definable", gfc_current_intrinsic
, &value
->where
);
1064 return gfc_check_atomic (atom
, value
);
1068 /* BESJN and BESYN functions. */
1071 gfc_check_besn (gfc_expr
*n
, gfc_expr
*x
)
1073 if (type_check (n
, 0, BT_INTEGER
) == FAILURE
)
1075 if (n
->expr_type
== EXPR_CONSTANT
)
1078 gfc_extract_int (n
, &i
);
1079 if (i
< 0 && gfc_notify_std (GFC_STD_GNU
, "Extension: Negative argument "
1080 "N at %L", &n
->where
) == FAILURE
)
1084 if (type_check (x
, 1, BT_REAL
) == FAILURE
)
1091 /* Transformational version of the Bessel JN and YN functions. */
1094 gfc_check_bessel_n2 (gfc_expr
*n1
, gfc_expr
*n2
, gfc_expr
*x
)
1096 if (type_check (n1
, 0, BT_INTEGER
) == FAILURE
)
1098 if (scalar_check (n1
, 0) == FAILURE
)
1100 if (nonnegative_check("N1", n1
) == FAILURE
)
1103 if (type_check (n2
, 1, BT_INTEGER
) == FAILURE
)
1105 if (scalar_check (n2
, 1) == FAILURE
)
1107 if (nonnegative_check("N2", n2
) == FAILURE
)
1110 if (type_check (x
, 2, BT_REAL
) == FAILURE
)
1112 if (scalar_check (x
, 2) == FAILURE
)
1120 gfc_check_bge_bgt_ble_blt (gfc_expr
*i
, gfc_expr
*j
)
1122 if (type_check (i
, 0, BT_INTEGER
) == FAILURE
)
1125 if (type_check (j
, 1, BT_INTEGER
) == FAILURE
)
1133 gfc_check_bitfcn (gfc_expr
*i
, gfc_expr
*pos
)
1135 if (type_check (i
, 0, BT_INTEGER
) == FAILURE
)
1138 if (type_check (pos
, 1, BT_INTEGER
) == FAILURE
)
1141 if (nonnegative_check ("pos", pos
) == FAILURE
)
1144 if (less_than_bitsize1 ("i", i
, "pos", pos
, false) == FAILURE
)
1152 gfc_check_char (gfc_expr
*i
, gfc_expr
*kind
)
1154 if (type_check (i
, 0, BT_INTEGER
) == FAILURE
)
1156 if (kind_check (kind
, 1, BT_CHARACTER
) == FAILURE
)
1164 gfc_check_chdir (gfc_expr
*dir
)
1166 if (type_check (dir
, 0, BT_CHARACTER
) == FAILURE
)
1168 if (kind_value_check (dir
, 0, gfc_default_character_kind
) == FAILURE
)
1176 gfc_check_chdir_sub (gfc_expr
*dir
, gfc_expr
*status
)
1178 if (type_check (dir
, 0, BT_CHARACTER
) == FAILURE
)
1180 if (kind_value_check (dir
, 0, gfc_default_character_kind
) == FAILURE
)
1186 if (type_check (status
, 1, BT_INTEGER
) == FAILURE
)
1188 if (scalar_check (status
, 1) == FAILURE
)
1196 gfc_check_chmod (gfc_expr
*name
, gfc_expr
*mode
)
1198 if (type_check (name
, 0, BT_CHARACTER
) == FAILURE
)
1200 if (kind_value_check (name
, 0, gfc_default_character_kind
) == FAILURE
)
1203 if (type_check (mode
, 1, BT_CHARACTER
) == FAILURE
)
1205 if (kind_value_check (mode
, 1, gfc_default_character_kind
) == FAILURE
)
1213 gfc_check_chmod_sub (gfc_expr
*name
, gfc_expr
*mode
, gfc_expr
*status
)
1215 if (type_check (name
, 0, BT_CHARACTER
) == FAILURE
)
1217 if (kind_value_check (name
, 0, gfc_default_character_kind
) == FAILURE
)
1220 if (type_check (mode
, 1, BT_CHARACTER
) == FAILURE
)
1222 if (kind_value_check (mode
, 1, gfc_default_character_kind
) == FAILURE
)
1228 if (type_check (status
, 2, BT_INTEGER
) == FAILURE
)
1231 if (scalar_check (status
, 2) == FAILURE
)
1239 gfc_check_cmplx (gfc_expr
*x
, gfc_expr
*y
, gfc_expr
*kind
)
1241 if (numeric_check (x
, 0) == FAILURE
)
1246 if (numeric_check (y
, 1) == FAILURE
)
1249 if (x
->ts
.type
== BT_COMPLEX
)
1251 gfc_error ("'%s' argument of '%s' intrinsic at %L must not be "
1252 "present if 'x' is COMPLEX",
1253 gfc_current_intrinsic_arg
[1]->name
, gfc_current_intrinsic
,
1258 if (y
->ts
.type
== BT_COMPLEX
)
1260 gfc_error ("'%s' argument of '%s' intrinsic at %L must have a type "
1261 "of either REAL or INTEGER",
1262 gfc_current_intrinsic_arg
[1]->name
, gfc_current_intrinsic
,
1269 if (kind_check (kind
, 2, BT_COMPLEX
) == FAILURE
)
1277 gfc_check_complex (gfc_expr
*x
, gfc_expr
*y
)
1279 if (int_or_real_check (x
, 0) == FAILURE
)
1281 if (scalar_check (x
, 0) == FAILURE
)
1284 if (int_or_real_check (y
, 1) == FAILURE
)
1286 if (scalar_check (y
, 1) == FAILURE
)
1294 gfc_check_count (gfc_expr
*mask
, gfc_expr
*dim
, gfc_expr
*kind
)
1296 if (logical_array_check (mask
, 0) == FAILURE
)
1298 if (dim_check (dim
, 1, false) == FAILURE
)
1300 if (dim_rank_check (dim
, mask
, 0) == FAILURE
)
1302 if (kind_check (kind
, 2, BT_INTEGER
) == FAILURE
)
1304 if (kind
&& gfc_notify_std (GFC_STD_F2003
, "Fortran 2003: '%s' intrinsic "
1305 "with KIND argument at %L",
1306 gfc_current_intrinsic
, &kind
->where
) == FAILURE
)
1314 gfc_check_cshift (gfc_expr
*array
, gfc_expr
*shift
, gfc_expr
*dim
)
1316 if (array_check (array
, 0) == FAILURE
)
1319 if (type_check (shift
, 1, BT_INTEGER
) == FAILURE
)
1322 if (dim_check (dim
, 2, true) == FAILURE
)
1325 if (dim_rank_check (dim
, array
, false) == FAILURE
)
1328 if (array
->rank
== 1 || shift
->rank
== 0)
1330 if (scalar_check (shift
, 1) == FAILURE
)
1333 else if (shift
->rank
== array
->rank
- 1)
1338 else if (dim
->expr_type
== EXPR_CONSTANT
)
1339 gfc_extract_int (dim
, &d
);
1346 for (i
= 0, j
= 0; i
< array
->rank
; i
++)
1349 if (!identical_dimen_shape (array
, i
, shift
, j
))
1351 gfc_error ("'%s' argument of '%s' intrinsic at %L has "
1352 "invalid shape in dimension %d (%ld/%ld)",
1353 gfc_current_intrinsic_arg
[1]->name
,
1354 gfc_current_intrinsic
, &shift
->where
, i
+ 1,
1355 mpz_get_si (array
->shape
[i
]),
1356 mpz_get_si (shift
->shape
[j
]));
1366 gfc_error ("'%s' argument of intrinsic '%s' at %L of must have rank "
1367 "%d or be a scalar", gfc_current_intrinsic_arg
[1]->name
,
1368 gfc_current_intrinsic
, &shift
->where
, array
->rank
- 1);
1377 gfc_check_ctime (gfc_expr
*time
)
1379 if (scalar_check (time
, 0) == FAILURE
)
1382 if (type_check (time
, 0, BT_INTEGER
) == FAILURE
)
1389 gfc_try
gfc_check_datan2 (gfc_expr
*y
, gfc_expr
*x
)
1391 if (double_check (y
, 0) == FAILURE
|| double_check (x
, 1) == FAILURE
)
1398 gfc_check_dcmplx (gfc_expr
*x
, gfc_expr
*y
)
1400 if (numeric_check (x
, 0) == FAILURE
)
1405 if (numeric_check (y
, 1) == FAILURE
)
1408 if (x
->ts
.type
== BT_COMPLEX
)
1410 gfc_error ("'%s' argument of '%s' intrinsic at %L must not be "
1411 "present if 'x' is COMPLEX",
1412 gfc_current_intrinsic_arg
[1]->name
, gfc_current_intrinsic
,
1417 if (y
->ts
.type
== BT_COMPLEX
)
1419 gfc_error ("'%s' argument of '%s' intrinsic at %L must have a type "
1420 "of either REAL or INTEGER",
1421 gfc_current_intrinsic_arg
[1]->name
, gfc_current_intrinsic
,
1432 gfc_check_dble (gfc_expr
*x
)
1434 if (numeric_check (x
, 0) == FAILURE
)
1442 gfc_check_digits (gfc_expr
*x
)
1444 if (int_or_real_check (x
, 0) == FAILURE
)
1452 gfc_check_dot_product (gfc_expr
*vector_a
, gfc_expr
*vector_b
)
1454 switch (vector_a
->ts
.type
)
1457 if (type_check (vector_b
, 1, BT_LOGICAL
) == FAILURE
)
1464 if (numeric_check (vector_b
, 1) == FAILURE
)
1469 gfc_error ("'%s' argument of '%s' intrinsic at %L must be numeric "
1470 "or LOGICAL", gfc_current_intrinsic_arg
[0]->name
,
1471 gfc_current_intrinsic
, &vector_a
->where
);
1475 if (rank_check (vector_a
, 0, 1) == FAILURE
)
1478 if (rank_check (vector_b
, 1, 1) == FAILURE
)
1481 if (! identical_dimen_shape (vector_a
, 0, vector_b
, 0))
1483 gfc_error ("Different shape for arguments '%s' and '%s' at %L for "
1484 "intrinsic 'dot_product'", gfc_current_intrinsic_arg
[0]->name
,
1485 gfc_current_intrinsic_arg
[1]->name
, &vector_a
->where
);
1494 gfc_check_dprod (gfc_expr
*x
, gfc_expr
*y
)
1496 if (type_check (x
, 0, BT_REAL
) == FAILURE
1497 || type_check (y
, 1, BT_REAL
) == FAILURE
)
1500 if (x
->ts
.kind
!= gfc_default_real_kind
)
1502 gfc_error ("'%s' argument of '%s' intrinsic at %L must be default "
1503 "real", gfc_current_intrinsic_arg
[0]->name
,
1504 gfc_current_intrinsic
, &x
->where
);
1508 if (y
->ts
.kind
!= gfc_default_real_kind
)
1510 gfc_error ("'%s' argument of '%s' intrinsic at %L must be default "
1511 "real", gfc_current_intrinsic_arg
[1]->name
,
1512 gfc_current_intrinsic
, &y
->where
);
1521 gfc_check_dshift (gfc_expr
*i
, gfc_expr
*j
, gfc_expr
*shift
)
1523 if (type_check (i
, 0, BT_INTEGER
) == FAILURE
)
1526 if (type_check (j
, 1, BT_INTEGER
) == FAILURE
)
1529 if (i
->is_boz
&& j
->is_boz
)
1531 gfc_error ("'I' at %L and 'J' at %L cannot both be BOZ literal "
1532 "constants", &i
->where
, &j
->where
);
1536 if (!i
->is_boz
&& !j
->is_boz
&& same_type_check (i
, 0, j
, 1) == FAILURE
)
1539 if (type_check (shift
, 2, BT_INTEGER
) == FAILURE
)
1542 if (nonnegative_check ("SHIFT", shift
) == FAILURE
)
1547 if (less_than_bitsize1 ("J", j
, "SHIFT", shift
, true) == FAILURE
)
1549 i
->ts
.kind
= j
->ts
.kind
;
1553 if (less_than_bitsize1 ("I", i
, "SHIFT", shift
, true) == FAILURE
)
1555 j
->ts
.kind
= i
->ts
.kind
;
1563 gfc_check_eoshift (gfc_expr
*array
, gfc_expr
*shift
, gfc_expr
*boundary
,
1566 if (array_check (array
, 0) == FAILURE
)
1569 if (type_check (shift
, 1, BT_INTEGER
) == FAILURE
)
1572 if (dim_check (dim
, 3, true) == FAILURE
)
1575 if (dim_rank_check (dim
, array
, false) == FAILURE
)
1578 if (array
->rank
== 1 || shift
->rank
== 0)
1580 if (scalar_check (shift
, 1) == FAILURE
)
1583 else if (shift
->rank
== array
->rank
- 1)
1588 else if (dim
->expr_type
== EXPR_CONSTANT
)
1589 gfc_extract_int (dim
, &d
);
1596 for (i
= 0, j
= 0; i
< array
->rank
; i
++)
1599 if (!identical_dimen_shape (array
, i
, shift
, j
))
1601 gfc_error ("'%s' argument of '%s' intrinsic at %L has "
1602 "invalid shape in dimension %d (%ld/%ld)",
1603 gfc_current_intrinsic_arg
[1]->name
,
1604 gfc_current_intrinsic
, &shift
->where
, i
+ 1,
1605 mpz_get_si (array
->shape
[i
]),
1606 mpz_get_si (shift
->shape
[j
]));
1616 gfc_error ("'%s' argument of intrinsic '%s' at %L of must have rank "
1617 "%d or be a scalar", gfc_current_intrinsic_arg
[1]->name
,
1618 gfc_current_intrinsic
, &shift
->where
, array
->rank
- 1);
1622 if (boundary
!= NULL
)
1624 if (same_type_check (array
, 0, boundary
, 2) == FAILURE
)
1627 if (array
->rank
== 1 || boundary
->rank
== 0)
1629 if (scalar_check (boundary
, 2) == FAILURE
)
1632 else if (boundary
->rank
== array
->rank
- 1)
1634 if (gfc_check_conformance (shift
, boundary
,
1635 "arguments '%s' and '%s' for "
1637 gfc_current_intrinsic_arg
[1]->name
,
1638 gfc_current_intrinsic_arg
[2]->name
,
1639 gfc_current_intrinsic
) == FAILURE
)
1644 gfc_error ("'%s' argument of intrinsic '%s' at %L of must have "
1645 "rank %d or be a scalar",
1646 gfc_current_intrinsic_arg
[1]->name
, gfc_current_intrinsic
,
1647 &shift
->where
, array
->rank
- 1);
1656 gfc_check_float (gfc_expr
*a
)
1658 if (type_check (a
, 0, BT_INTEGER
) == FAILURE
)
1661 if ((a
->ts
.kind
!= gfc_default_integer_kind
)
1662 && gfc_notify_std (GFC_STD_GNU
, "GNU extension: non-default INTEGER "
1663 "kind argument to %s intrinsic at %L",
1664 gfc_current_intrinsic
, &a
->where
) == FAILURE
)
1670 /* A single complex argument. */
1673 gfc_check_fn_c (gfc_expr
*a
)
1675 if (type_check (a
, 0, BT_COMPLEX
) == FAILURE
)
1681 /* A single real argument. */
1684 gfc_check_fn_r (gfc_expr
*a
)
1686 if (type_check (a
, 0, BT_REAL
) == FAILURE
)
1692 /* A single double argument. */
1695 gfc_check_fn_d (gfc_expr
*a
)
1697 if (double_check (a
, 0) == FAILURE
)
1703 /* A single real or complex argument. */
1706 gfc_check_fn_rc (gfc_expr
*a
)
1708 if (real_or_complex_check (a
, 0) == FAILURE
)
1716 gfc_check_fn_rc2008 (gfc_expr
*a
)
1718 if (real_or_complex_check (a
, 0) == FAILURE
)
1721 if (a
->ts
.type
== BT_COMPLEX
1722 && gfc_notify_std (GFC_STD_F2008
, "Fortran 2008: COMPLEX argument '%s' "
1723 "argument of '%s' intrinsic at %L",
1724 gfc_current_intrinsic_arg
[0]->name
,
1725 gfc_current_intrinsic
, &a
->where
) == FAILURE
)
1733 gfc_check_fnum (gfc_expr
*unit
)
1735 if (type_check (unit
, 0, BT_INTEGER
) == FAILURE
)
1738 if (scalar_check (unit
, 0) == FAILURE
)
1746 gfc_check_huge (gfc_expr
*x
)
1748 if (int_or_real_check (x
, 0) == FAILURE
)
1756 gfc_check_hypot (gfc_expr
*x
, gfc_expr
*y
)
1758 if (type_check (x
, 0, BT_REAL
) == FAILURE
)
1760 if (same_type_check (x
, 0, y
, 1) == FAILURE
)
1767 /* Check that the single argument is an integer. */
1770 gfc_check_i (gfc_expr
*i
)
1772 if (type_check (i
, 0, BT_INTEGER
) == FAILURE
)
1780 gfc_check_iand (gfc_expr
*i
, gfc_expr
*j
)
1782 if (type_check (i
, 0, BT_INTEGER
) == FAILURE
)
1785 if (type_check (j
, 1, BT_INTEGER
) == FAILURE
)
1788 if (i
->ts
.kind
!= j
->ts
.kind
)
1790 if (gfc_notify_std (GFC_STD_GNU
, "Extension: Different type kinds at %L",
1791 &i
->where
) == FAILURE
)
1800 gfc_check_ibits (gfc_expr
*i
, gfc_expr
*pos
, gfc_expr
*len
)
1802 if (type_check (i
, 0, BT_INTEGER
) == FAILURE
)
1805 if (type_check (pos
, 1, BT_INTEGER
) == FAILURE
)
1808 if (type_check (len
, 2, BT_INTEGER
) == FAILURE
)
1811 if (nonnegative_check ("pos", pos
) == FAILURE
)
1814 if (nonnegative_check ("len", len
) == FAILURE
)
1817 if (less_than_bitsize2 ("i", i
, "pos", pos
, "len", len
) == FAILURE
)
1825 gfc_check_ichar_iachar (gfc_expr
*c
, gfc_expr
*kind
)
1829 if (type_check (c
, 0, BT_CHARACTER
) == FAILURE
)
1832 if (kind_check (kind
, 1, BT_INTEGER
) == FAILURE
)
1835 if (kind
&& gfc_notify_std (GFC_STD_F2003
, "Fortran 2003: '%s' intrinsic "
1836 "with KIND argument at %L",
1837 gfc_current_intrinsic
, &kind
->where
) == FAILURE
)
1840 if (c
->expr_type
== EXPR_VARIABLE
|| c
->expr_type
== EXPR_SUBSTRING
)
1846 /* Substring references don't have the charlength set. */
1848 while (ref
&& ref
->type
!= REF_SUBSTRING
)
1851 gcc_assert (ref
== NULL
|| ref
->type
== REF_SUBSTRING
);
1855 /* Check that the argument is length one. Non-constant lengths
1856 can't be checked here, so assume they are ok. */
1857 if (c
->ts
.u
.cl
&& c
->ts
.u
.cl
->length
)
1859 /* If we already have a length for this expression then use it. */
1860 if (c
->ts
.u
.cl
->length
->expr_type
!= EXPR_CONSTANT
)
1862 i
= mpz_get_si (c
->ts
.u
.cl
->length
->value
.integer
);
1869 start
= ref
->u
.ss
.start
;
1870 end
= ref
->u
.ss
.end
;
1873 if (end
== NULL
|| end
->expr_type
!= EXPR_CONSTANT
1874 || start
->expr_type
!= EXPR_CONSTANT
)
1877 i
= mpz_get_si (end
->value
.integer
) + 1
1878 - mpz_get_si (start
->value
.integer
);
1886 gfc_error ("Argument of %s at %L must be of length one",
1887 gfc_current_intrinsic
, &c
->where
);
1896 gfc_check_idnint (gfc_expr
*a
)
1898 if (double_check (a
, 0) == FAILURE
)
1906 gfc_check_ieor (gfc_expr
*i
, gfc_expr
*j
)
1908 if (type_check (i
, 0, BT_INTEGER
) == FAILURE
)
1911 if (type_check (j
, 1, BT_INTEGER
) == FAILURE
)
1914 if (i
->ts
.kind
!= j
->ts
.kind
)
1916 if (gfc_notify_std (GFC_STD_GNU
, "Extension: Different type kinds at %L",
1917 &i
->where
) == FAILURE
)
1926 gfc_check_index (gfc_expr
*string
, gfc_expr
*substring
, gfc_expr
*back
,
1929 if (type_check (string
, 0, BT_CHARACTER
) == FAILURE
1930 || type_check (substring
, 1, BT_CHARACTER
) == FAILURE
)
1933 if (back
!= NULL
&& type_check (back
, 2, BT_LOGICAL
) == FAILURE
)
1936 if (kind_check (kind
, 3, BT_INTEGER
) == FAILURE
)
1938 if (kind
&& gfc_notify_std (GFC_STD_F2003
, "Fortran 2003: '%s' intrinsic "
1939 "with KIND argument at %L",
1940 gfc_current_intrinsic
, &kind
->where
) == FAILURE
)
1943 if (string
->ts
.kind
!= substring
->ts
.kind
)
1945 gfc_error ("'%s' argument of '%s' intrinsic at %L must be the same "
1946 "kind as '%s'", gfc_current_intrinsic_arg
[1]->name
,
1947 gfc_current_intrinsic
, &substring
->where
,
1948 gfc_current_intrinsic_arg
[0]->name
);
1957 gfc_check_int (gfc_expr
*x
, gfc_expr
*kind
)
1959 if (numeric_check (x
, 0) == FAILURE
)
1962 if (kind_check (kind
, 1, BT_INTEGER
) == FAILURE
)
1970 gfc_check_intconv (gfc_expr
*x
)
1972 if (numeric_check (x
, 0) == FAILURE
)
1980 gfc_check_ior (gfc_expr
*i
, gfc_expr
*j
)
1982 if (type_check (i
, 0, BT_INTEGER
) == FAILURE
)
1985 if (type_check (j
, 1, BT_INTEGER
) == FAILURE
)
1988 if (i
->ts
.kind
!= j
->ts
.kind
)
1990 if (gfc_notify_std (GFC_STD_GNU
, "Extension: Different type kinds at %L",
1991 &i
->where
) == FAILURE
)
2000 gfc_check_ishft (gfc_expr
*i
, gfc_expr
*shift
)
2002 if (type_check (i
, 0, BT_INTEGER
) == FAILURE
2003 || type_check (shift
, 1, BT_INTEGER
) == FAILURE
)
2006 if (less_than_bitsize1 ("I", i
, NULL
, shift
, true) == FAILURE
)
2014 gfc_check_ishftc (gfc_expr
*i
, gfc_expr
*shift
, gfc_expr
*size
)
2016 if (type_check (i
, 0, BT_INTEGER
) == FAILURE
2017 || type_check (shift
, 1, BT_INTEGER
) == FAILURE
)
2024 if (type_check (size
, 2, BT_INTEGER
) == FAILURE
)
2027 if (less_than_bitsize1 ("I", i
, "SIZE", size
, true) == FAILURE
)
2030 if (size
->expr_type
== EXPR_CONSTANT
)
2032 gfc_extract_int (size
, &i3
);
2035 gfc_error ("SIZE at %L must be positive", &size
->where
);
2039 if (shift
->expr_type
== EXPR_CONSTANT
)
2041 gfc_extract_int (shift
, &i2
);
2047 gfc_error ("The absolute value of SHIFT at %L must be less "
2048 "than or equal to SIZE at %L", &shift
->where
,
2055 else if (less_than_bitsize1 ("I", i
, NULL
, shift
, true) == FAILURE
)
2063 gfc_check_kill (gfc_expr
*pid
, gfc_expr
*sig
)
2065 if (type_check (pid
, 0, BT_INTEGER
) == FAILURE
)
2068 if (type_check (sig
, 1, BT_INTEGER
) == FAILURE
)
2076 gfc_check_kill_sub (gfc_expr
*pid
, gfc_expr
*sig
, gfc_expr
*status
)
2078 if (type_check (pid
, 0, BT_INTEGER
) == FAILURE
)
2081 if (scalar_check (pid
, 0) == FAILURE
)
2084 if (type_check (sig
, 1, BT_INTEGER
) == FAILURE
)
2087 if (scalar_check (sig
, 1) == FAILURE
)
2093 if (type_check (status
, 2, BT_INTEGER
) == FAILURE
)
2096 if (scalar_check (status
, 2) == FAILURE
)
2104 gfc_check_kind (gfc_expr
*x
)
2106 if (x
->ts
.type
== BT_DERIVED
)
2108 gfc_error ("'%s' argument of '%s' intrinsic at %L must be a "
2109 "non-derived type", gfc_current_intrinsic_arg
[0]->name
,
2110 gfc_current_intrinsic
, &x
->where
);
2119 gfc_check_lbound (gfc_expr
*array
, gfc_expr
*dim
, gfc_expr
*kind
)
2121 if (array_check (array
, 0) == FAILURE
)
2124 if (dim_check (dim
, 1, false) == FAILURE
)
2127 if (dim_rank_check (dim
, array
, 1) == FAILURE
)
2130 if (kind_check (kind
, 2, BT_INTEGER
) == FAILURE
)
2132 if (kind
&& gfc_notify_std (GFC_STD_F2003
, "Fortran 2003: '%s' intrinsic "
2133 "with KIND argument at %L",
2134 gfc_current_intrinsic
, &kind
->where
) == FAILURE
)
2142 gfc_check_lcobound (gfc_expr
*coarray
, gfc_expr
*dim
, gfc_expr
*kind
)
2144 if (gfc_option
.coarray
== GFC_FCOARRAY_NONE
)
2146 gfc_fatal_error ("Coarrays disabled at %C, use -fcoarray= to enable");
2150 if (coarray_check (coarray
, 0) == FAILURE
)
2155 if (dim_check (dim
, 1, false) == FAILURE
)
2158 if (dim_corank_check (dim
, coarray
) == FAILURE
)
2162 if (kind_check (kind
, 2, BT_INTEGER
) == FAILURE
)
2170 gfc_check_len_lentrim (gfc_expr
*s
, gfc_expr
*kind
)
2172 if (type_check (s
, 0, BT_CHARACTER
) == FAILURE
)
2175 if (kind_check (kind
, 1, BT_INTEGER
) == FAILURE
)
2177 if (kind
&& gfc_notify_std (GFC_STD_F2003
, "Fortran 2003: '%s' intrinsic "
2178 "with KIND argument at %L",
2179 gfc_current_intrinsic
, &kind
->where
) == FAILURE
)
2187 gfc_check_lge_lgt_lle_llt (gfc_expr
*a
, gfc_expr
*b
)
2189 if (type_check (a
, 0, BT_CHARACTER
) == FAILURE
)
2191 if (kind_value_check (a
, 0, gfc_default_character_kind
) == FAILURE
)
2194 if (type_check (b
, 1, BT_CHARACTER
) == FAILURE
)
2196 if (kind_value_check (b
, 1, gfc_default_character_kind
) == FAILURE
)
2204 gfc_check_link (gfc_expr
*path1
, gfc_expr
*path2
)
2206 if (type_check (path1
, 0, BT_CHARACTER
) == FAILURE
)
2208 if (kind_value_check (path1
, 0, gfc_default_character_kind
) == FAILURE
)
2211 if (type_check (path2
, 1, BT_CHARACTER
) == FAILURE
)
2213 if (kind_value_check (path2
, 1, gfc_default_character_kind
) == FAILURE
)
2221 gfc_check_link_sub (gfc_expr
*path1
, gfc_expr
*path2
, gfc_expr
*status
)
2223 if (type_check (path1
, 0, BT_CHARACTER
) == FAILURE
)
2225 if (kind_value_check (path1
, 0, gfc_default_character_kind
) == FAILURE
)
2228 if (type_check (path2
, 1, BT_CHARACTER
) == FAILURE
)
2230 if (kind_value_check (path2
, 0, gfc_default_character_kind
) == FAILURE
)
2236 if (type_check (status
, 2, BT_INTEGER
) == FAILURE
)
2239 if (scalar_check (status
, 2) == FAILURE
)
2247 gfc_check_loc (gfc_expr
*expr
)
2249 return variable_check (expr
, 0, true);
2254 gfc_check_symlnk (gfc_expr
*path1
, gfc_expr
*path2
)
2256 if (type_check (path1
, 0, BT_CHARACTER
) == FAILURE
)
2258 if (kind_value_check (path1
, 0, gfc_default_character_kind
) == FAILURE
)
2261 if (type_check (path2
, 1, BT_CHARACTER
) == FAILURE
)
2263 if (kind_value_check (path2
, 1, gfc_default_character_kind
) == FAILURE
)
2271 gfc_check_symlnk_sub (gfc_expr
*path1
, gfc_expr
*path2
, gfc_expr
*status
)
2273 if (type_check (path1
, 0, BT_CHARACTER
) == FAILURE
)
2275 if (kind_value_check (path1
, 0, gfc_default_character_kind
) == FAILURE
)
2278 if (type_check (path2
, 1, BT_CHARACTER
) == FAILURE
)
2280 if (kind_value_check (path2
, 1, gfc_default_character_kind
) == FAILURE
)
2286 if (type_check (status
, 2, BT_INTEGER
) == FAILURE
)
2289 if (scalar_check (status
, 2) == FAILURE
)
2297 gfc_check_logical (gfc_expr
*a
, gfc_expr
*kind
)
2299 if (type_check (a
, 0, BT_LOGICAL
) == FAILURE
)
2301 if (kind_check (kind
, 1, BT_LOGICAL
) == FAILURE
)
2308 /* Min/max family. */
2311 min_max_args (gfc_actual_arglist
*arg
)
2313 if (arg
== NULL
|| arg
->next
== NULL
)
2315 gfc_error ("Intrinsic '%s' at %L must have at least two arguments",
2316 gfc_current_intrinsic
, gfc_current_intrinsic_where
);
2325 check_rest (bt type
, int kind
, gfc_actual_arglist
*arglist
)
2327 gfc_actual_arglist
*arg
, *tmp
;
2332 if (min_max_args (arglist
) == FAILURE
)
2335 for (arg
= arglist
, n
=1; arg
; arg
= arg
->next
, n
++)
2338 if (x
->ts
.type
!= type
|| x
->ts
.kind
!= kind
)
2340 if (x
->ts
.type
== type
)
2342 if (gfc_notify_std (GFC_STD_GNU
, "Extension: Different type "
2343 "kinds at %L", &x
->where
) == FAILURE
)
2348 gfc_error ("'a%d' argument of '%s' intrinsic at %L must be "
2349 "%s(%d)", n
, gfc_current_intrinsic
, &x
->where
,
2350 gfc_basic_typename (type
), kind
);
2355 for (tmp
= arglist
, m
=1; tmp
!= arg
; tmp
= tmp
->next
, m
++)
2356 if (gfc_check_conformance (tmp
->expr
, x
,
2357 "arguments 'a%d' and 'a%d' for "
2358 "intrinsic '%s'", m
, n
,
2359 gfc_current_intrinsic
) == FAILURE
)
2368 gfc_check_min_max (gfc_actual_arglist
*arg
)
2372 if (min_max_args (arg
) == FAILURE
)
2377 if (x
->ts
.type
== BT_CHARACTER
)
2379 if (gfc_notify_std (GFC_STD_F2003
, "Fortran 2003: '%s' intrinsic "
2380 "with CHARACTER argument at %L",
2381 gfc_current_intrinsic
, &x
->where
) == FAILURE
)
2384 else if (x
->ts
.type
!= BT_INTEGER
&& x
->ts
.type
!= BT_REAL
)
2386 gfc_error ("'a1' argument of '%s' intrinsic at %L must be INTEGER, "
2387 "REAL or CHARACTER", gfc_current_intrinsic
, &x
->where
);
2391 return check_rest (x
->ts
.type
, x
->ts
.kind
, arg
);
2396 gfc_check_min_max_integer (gfc_actual_arglist
*arg
)
2398 return check_rest (BT_INTEGER
, gfc_default_integer_kind
, arg
);
2403 gfc_check_min_max_real (gfc_actual_arglist
*arg
)
2405 return check_rest (BT_REAL
, gfc_default_real_kind
, arg
);
2410 gfc_check_min_max_double (gfc_actual_arglist
*arg
)
2412 return check_rest (BT_REAL
, gfc_default_double_kind
, arg
);
2416 /* End of min/max family. */
2419 gfc_check_malloc (gfc_expr
*size
)
2421 if (type_check (size
, 0, BT_INTEGER
) == FAILURE
)
2424 if (scalar_check (size
, 0) == FAILURE
)
2432 gfc_check_matmul (gfc_expr
*matrix_a
, gfc_expr
*matrix_b
)
2434 if ((matrix_a
->ts
.type
!= BT_LOGICAL
) && !gfc_numeric_ts (&matrix_a
->ts
))
2436 gfc_error ("'%s' argument of '%s' intrinsic at %L must be numeric "
2437 "or LOGICAL", gfc_current_intrinsic_arg
[0]->name
,
2438 gfc_current_intrinsic
, &matrix_a
->where
);
2442 if ((matrix_b
->ts
.type
!= BT_LOGICAL
) && !gfc_numeric_ts (&matrix_b
->ts
))
2444 gfc_error ("'%s' argument of '%s' intrinsic at %L must be numeric "
2445 "or LOGICAL", gfc_current_intrinsic_arg
[1]->name
,
2446 gfc_current_intrinsic
, &matrix_b
->where
);
2450 if ((matrix_a
->ts
.type
== BT_LOGICAL
&& gfc_numeric_ts (&matrix_b
->ts
))
2451 || (gfc_numeric_ts (&matrix_a
->ts
) && matrix_b
->ts
.type
== BT_LOGICAL
))
2453 gfc_error ("Argument types of '%s' intrinsic at %L must match (%s/%s)",
2454 gfc_current_intrinsic
, &matrix_a
->where
,
2455 gfc_typename(&matrix_a
->ts
), gfc_typename(&matrix_b
->ts
));
2459 switch (matrix_a
->rank
)
2462 if (rank_check (matrix_b
, 1, 2) == FAILURE
)
2464 /* Check for case matrix_a has shape(m), matrix_b has shape (m, k). */
2465 if (!identical_dimen_shape (matrix_a
, 0, matrix_b
, 0))
2467 gfc_error ("Different shape on dimension 1 for arguments '%s' "
2468 "and '%s' at %L for intrinsic matmul",
2469 gfc_current_intrinsic_arg
[0]->name
,
2470 gfc_current_intrinsic_arg
[1]->name
, &matrix_a
->where
);
2476 if (matrix_b
->rank
!= 2)
2478 if (rank_check (matrix_b
, 1, 1) == FAILURE
)
2481 /* matrix_b has rank 1 or 2 here. Common check for the cases
2482 - matrix_a has shape (n,m) and matrix_b has shape (m, k)
2483 - matrix_a has shape (n,m) and matrix_b has shape (m). */
2484 if (!identical_dimen_shape (matrix_a
, 1, matrix_b
, 0))
2486 gfc_error ("Different shape on dimension 2 for argument '%s' and "
2487 "dimension 1 for argument '%s' at %L for intrinsic "
2488 "matmul", gfc_current_intrinsic_arg
[0]->name
,
2489 gfc_current_intrinsic_arg
[1]->name
, &matrix_a
->where
);
2495 gfc_error ("'%s' argument of '%s' intrinsic at %L must be of rank "
2496 "1 or 2", gfc_current_intrinsic_arg
[0]->name
,
2497 gfc_current_intrinsic
, &matrix_a
->where
);
2505 /* Whoever came up with this interface was probably on something.
2506 The possibilities for the occupation of the second and third
2513 NULL MASK minloc(array, mask=m)
2516 I.e. in the case of minloc(array,mask), mask will be in the second
2517 position of the argument list and we'll have to fix that up. */
2520 gfc_check_minloc_maxloc (gfc_actual_arglist
*ap
)
2522 gfc_expr
*a
, *m
, *d
;
2525 if (int_or_real_check (a
, 0) == FAILURE
|| array_check (a
, 0) == FAILURE
)
2529 m
= ap
->next
->next
->expr
;
2531 if (m
== NULL
&& d
!= NULL
&& d
->ts
.type
== BT_LOGICAL
2532 && ap
->next
->name
== NULL
)
2536 ap
->next
->expr
= NULL
;
2537 ap
->next
->next
->expr
= m
;
2540 if (dim_check (d
, 1, false) == FAILURE
)
2543 if (dim_rank_check (d
, a
, 0) == FAILURE
)
2546 if (m
!= NULL
&& type_check (m
, 2, BT_LOGICAL
) == FAILURE
)
2550 && gfc_check_conformance (a
, m
,
2551 "arguments '%s' and '%s' for intrinsic %s",
2552 gfc_current_intrinsic_arg
[0]->name
,
2553 gfc_current_intrinsic_arg
[2]->name
,
2554 gfc_current_intrinsic
) == FAILURE
)
2561 /* Similar to minloc/maxloc, the argument list might need to be
2562 reordered for the MINVAL, MAXVAL, PRODUCT, and SUM intrinsics. The
2563 difference is that MINLOC/MAXLOC take an additional KIND argument.
2564 The possibilities are:
2570 NULL MASK minval(array, mask=m)
2573 I.e. in the case of minval(array,mask), mask will be in the second
2574 position of the argument list and we'll have to fix that up. */
2577 check_reduction (gfc_actual_arglist
*ap
)
2579 gfc_expr
*a
, *m
, *d
;
2583 m
= ap
->next
->next
->expr
;
2585 if (m
== NULL
&& d
!= NULL
&& d
->ts
.type
== BT_LOGICAL
2586 && ap
->next
->name
== NULL
)
2590 ap
->next
->expr
= NULL
;
2591 ap
->next
->next
->expr
= m
;
2594 if (dim_check (d
, 1, false) == FAILURE
)
2597 if (dim_rank_check (d
, a
, 0) == FAILURE
)
2600 if (m
!= NULL
&& type_check (m
, 2, BT_LOGICAL
) == FAILURE
)
2604 && gfc_check_conformance (a
, m
,
2605 "arguments '%s' and '%s' for intrinsic %s",
2606 gfc_current_intrinsic_arg
[0]->name
,
2607 gfc_current_intrinsic_arg
[2]->name
,
2608 gfc_current_intrinsic
) == FAILURE
)
2616 gfc_check_minval_maxval (gfc_actual_arglist
*ap
)
2618 if (int_or_real_check (ap
->expr
, 0) == FAILURE
2619 || array_check (ap
->expr
, 0) == FAILURE
)
2622 return check_reduction (ap
);
2627 gfc_check_product_sum (gfc_actual_arglist
*ap
)
2629 if (numeric_check (ap
->expr
, 0) == FAILURE
2630 || array_check (ap
->expr
, 0) == FAILURE
)
2633 return check_reduction (ap
);
2637 /* For IANY, IALL and IPARITY. */
2640 gfc_check_mask (gfc_expr
*i
, gfc_expr
*kind
)
2644 if (type_check (i
, 0, BT_INTEGER
) == FAILURE
)
2647 if (nonnegative_check ("I", i
) == FAILURE
)
2650 if (kind_check (kind
, 1, BT_INTEGER
) == FAILURE
)
2654 gfc_extract_int (kind
, &k
);
2656 k
= gfc_default_integer_kind
;
2658 if (less_than_bitsizekind ("I", i
, k
) == FAILURE
)
2666 gfc_check_transf_bit_intrins (gfc_actual_arglist
*ap
)
2668 if (ap
->expr
->ts
.type
!= BT_INTEGER
)
2670 gfc_error ("'%s' argument of '%s' intrinsic at %L must be INTEGER",
2671 gfc_current_intrinsic_arg
[0]->name
,
2672 gfc_current_intrinsic
, &ap
->expr
->where
);
2676 if (array_check (ap
->expr
, 0) == FAILURE
)
2679 return check_reduction (ap
);
2684 gfc_check_merge (gfc_expr
*tsource
, gfc_expr
*fsource
, gfc_expr
*mask
)
2686 if (same_type_check (tsource
, 0, fsource
, 1) == FAILURE
)
2689 if (type_check (mask
, 2, BT_LOGICAL
) == FAILURE
)
2692 if (tsource
->ts
.type
== BT_CHARACTER
)
2693 return gfc_check_same_strlen (tsource
, fsource
, "MERGE intrinsic");
2700 gfc_check_merge_bits (gfc_expr
*i
, gfc_expr
*j
, gfc_expr
*mask
)
2702 if (type_check (i
, 0, BT_INTEGER
) == FAILURE
)
2705 if (type_check (j
, 1, BT_INTEGER
) == FAILURE
)
2708 if (type_check (mask
, 2, BT_INTEGER
) == FAILURE
)
2711 if (same_type_check (i
, 0, j
, 1) == FAILURE
)
2714 if (same_type_check (i
, 0, mask
, 2) == FAILURE
)
2722 gfc_check_move_alloc (gfc_expr
*from
, gfc_expr
*to
)
2724 if (variable_check (from
, 0, false) == FAILURE
)
2726 if (allocatable_check (from
, 0) == FAILURE
)
2729 if (variable_check (to
, 1, false) == FAILURE
)
2731 if (allocatable_check (to
, 1) == FAILURE
)
2734 if (from
->ts
.type
== BT_CLASS
&& to
->ts
.type
== BT_DERIVED
)
2736 gfc_error ("The TO arguments in MOVE_ALLOC at %L must be "
2737 "polymorphic if FROM is polymorphic",
2742 if (same_type_check (to
, 1, from
, 0) == FAILURE
)
2745 if (to
->rank
!= from
->rank
)
2747 gfc_error ("the '%s' and '%s' arguments of '%s' intrinsic at %L must "
2748 "have the same rank %d/%d", gfc_current_intrinsic_arg
[0]->name
,
2749 gfc_current_intrinsic_arg
[1]->name
, gfc_current_intrinsic
,
2750 &to
->where
, from
->rank
, to
->rank
);
2754 if (to
->ts
.kind
!= from
->ts
.kind
)
2756 gfc_error ("the '%s' and '%s' arguments of '%s' intrinsic at %L must "
2757 "be of the same kind %d/%d",
2758 gfc_current_intrinsic_arg
[0]->name
,
2759 gfc_current_intrinsic_arg
[1]->name
, gfc_current_intrinsic
,
2760 &to
->where
, from
->ts
.kind
, to
->ts
.kind
);
2764 /* CLASS arguments: Make sure the vtab of from is present. */
2765 if (to
->ts
.type
== BT_CLASS
)
2766 gfc_find_derived_vtab (from
->ts
.u
.derived
);
2773 gfc_check_nearest (gfc_expr
*x
, gfc_expr
*s
)
2775 if (type_check (x
, 0, BT_REAL
) == FAILURE
)
2778 if (type_check (s
, 1, BT_REAL
) == FAILURE
)
2781 if (s
->expr_type
== EXPR_CONSTANT
)
2783 if (mpfr_sgn (s
->value
.real
) == 0)
2785 gfc_error ("Argument 'S' of NEAREST at %L shall not be zero",
2796 gfc_check_new_line (gfc_expr
*a
)
2798 if (type_check (a
, 0, BT_CHARACTER
) == FAILURE
)
2806 gfc_check_norm2 (gfc_expr
*array
, gfc_expr
*dim
)
2808 if (type_check (array
, 0, BT_REAL
) == FAILURE
)
2811 if (array_check (array
, 0) == FAILURE
)
2814 if (dim_rank_check (dim
, array
, false) == FAILURE
)
2821 gfc_check_null (gfc_expr
*mold
)
2823 symbol_attribute attr
;
2828 if (variable_check (mold
, 0, true) == FAILURE
)
2831 attr
= gfc_variable_attr (mold
, NULL
);
2833 if (!attr
.pointer
&& !attr
.proc_pointer
&& !attr
.allocatable
)
2835 gfc_error ("'%s' argument of '%s' intrinsic at %L must be a POINTER, "
2836 "ALLOCATABLE or procedure pointer",
2837 gfc_current_intrinsic_arg
[0]->name
,
2838 gfc_current_intrinsic
, &mold
->where
);
2842 if (attr
.allocatable
2843 && gfc_notify_std (GFC_STD_F2003
, "Fortran 2003: NULL intrinsic with "
2844 "allocatable MOLD at %L", &mold
->where
) == FAILURE
)
2848 if (gfc_is_coindexed (mold
))
2850 gfc_error ("'%s' argument of '%s' intrinsic at %L shall not be "
2851 "conindexed", gfc_current_intrinsic_arg
[0]->name
,
2852 gfc_current_intrinsic
, &mold
->where
);
2861 gfc_check_pack (gfc_expr
*array
, gfc_expr
*mask
, gfc_expr
*vector
)
2863 if (array_check (array
, 0) == FAILURE
)
2866 if (type_check (mask
, 1, BT_LOGICAL
) == FAILURE
)
2869 if (gfc_check_conformance (array
, mask
,
2870 "arguments '%s' and '%s' for intrinsic '%s'",
2871 gfc_current_intrinsic_arg
[0]->name
,
2872 gfc_current_intrinsic_arg
[1]->name
,
2873 gfc_current_intrinsic
) == FAILURE
)
2878 mpz_t array_size
, vector_size
;
2879 bool have_array_size
, have_vector_size
;
2881 if (same_type_check (array
, 0, vector
, 2) == FAILURE
)
2884 if (rank_check (vector
, 2, 1) == FAILURE
)
2887 /* VECTOR requires at least as many elements as MASK
2888 has .TRUE. values. */
2889 have_array_size
= gfc_array_size (array
, &array_size
) == SUCCESS
;
2890 have_vector_size
= gfc_array_size (vector
, &vector_size
) == SUCCESS
;
2892 if (have_vector_size
2893 && (mask
->expr_type
== EXPR_ARRAY
2894 || (mask
->expr_type
== EXPR_CONSTANT
2895 && have_array_size
)))
2897 int mask_true_values
= 0;
2899 if (mask
->expr_type
== EXPR_ARRAY
)
2901 gfc_constructor
*mask_ctor
;
2902 mask_ctor
= gfc_constructor_first (mask
->value
.constructor
);
2905 if (mask_ctor
->expr
->expr_type
!= EXPR_CONSTANT
)
2907 mask_true_values
= 0;
2911 if (mask_ctor
->expr
->value
.logical
)
2914 mask_ctor
= gfc_constructor_next (mask_ctor
);
2917 else if (mask
->expr_type
== EXPR_CONSTANT
&& mask
->value
.logical
)
2918 mask_true_values
= mpz_get_si (array_size
);
2920 if (mpz_get_si (vector_size
) < mask_true_values
)
2922 gfc_error ("'%s' argument of '%s' intrinsic at %L must "
2923 "provide at least as many elements as there "
2924 "are .TRUE. values in '%s' (%ld/%d)",
2925 gfc_current_intrinsic_arg
[2]->name
,
2926 gfc_current_intrinsic
, &vector
->where
,
2927 gfc_current_intrinsic_arg
[1]->name
,
2928 mpz_get_si (vector_size
), mask_true_values
);
2933 if (have_array_size
)
2934 mpz_clear (array_size
);
2935 if (have_vector_size
)
2936 mpz_clear (vector_size
);
2944 gfc_check_parity (gfc_expr
*mask
, gfc_expr
*dim
)
2946 if (type_check (mask
, 0, BT_LOGICAL
) == FAILURE
)
2949 if (array_check (mask
, 0) == FAILURE
)
2952 if (dim_rank_check (dim
, mask
, false) == FAILURE
)
2960 gfc_check_precision (gfc_expr
*x
)
2962 if (real_or_complex_check (x
, 0) == FAILURE
)
2970 gfc_check_present (gfc_expr
*a
)
2974 if (variable_check (a
, 0, true) == FAILURE
)
2977 sym
= a
->symtree
->n
.sym
;
2978 if (!sym
->attr
.dummy
)
2980 gfc_error ("'%s' argument of '%s' intrinsic at %L must be of a "
2981 "dummy variable", gfc_current_intrinsic_arg
[0]->name
,
2982 gfc_current_intrinsic
, &a
->where
);
2986 if (!sym
->attr
.optional
)
2988 gfc_error ("'%s' argument of '%s' intrinsic at %L must be of "
2989 "an OPTIONAL dummy variable",
2990 gfc_current_intrinsic_arg
[0]->name
, gfc_current_intrinsic
,
2995 /* 13.14.82 PRESENT(A)
2997 Argument. A shall be the name of an optional dummy argument that is
2998 accessible in the subprogram in which the PRESENT function reference
3002 && !(a
->ref
->next
== NULL
&& a
->ref
->type
== REF_ARRAY
3003 && (a
->ref
->u
.ar
.type
== AR_FULL
3004 || (a
->ref
->u
.ar
.type
== AR_ELEMENT
3005 && a
->ref
->u
.ar
.as
->rank
== 0))))
3007 gfc_error ("'%s' argument of '%s' intrinsic at %L must not be a "
3008 "subobject of '%s'", gfc_current_intrinsic_arg
[0]->name
,
3009 gfc_current_intrinsic
, &a
->where
, sym
->name
);
3018 gfc_check_radix (gfc_expr
*x
)
3020 if (int_or_real_check (x
, 0) == FAILURE
)
3028 gfc_check_range (gfc_expr
*x
)
3030 if (numeric_check (x
, 0) == FAILURE
)
3038 gfc_check_rank (gfc_expr
*a ATTRIBUTE_UNUSED
)
3040 /* Any data object is allowed; a "data object" is a "constant (4.1.3),
3041 variable (6), or subobject of a constant (2.4.3.2.3)" (F2008, 1.3.45). */
3043 bool is_variable
= true;
3045 /* Functions returning pointers are regarded as variable, cf. F2008, R602. */
3046 if (a
->expr_type
== EXPR_FUNCTION
)
3047 is_variable
= a
->value
.function
.esym
3048 ? a
->value
.function
.esym
->result
->attr
.pointer
3049 : a
->symtree
->n
.sym
->result
->attr
.pointer
;
3051 if (a
->expr_type
== EXPR_OP
|| a
->expr_type
== EXPR_NULL
3052 || a
->expr_type
== EXPR_COMPCALL
|| a
->expr_type
== EXPR_PPC
3055 gfc_error ("The argument of the RANK intrinsic at %L must be a data "
3056 "object", &a
->where
);
3064 /* real, float, sngl. */
3066 gfc_check_real (gfc_expr
*a
, gfc_expr
*kind
)
3068 if (numeric_check (a
, 0) == FAILURE
)
3071 if (kind_check (kind
, 1, BT_REAL
) == FAILURE
)
3079 gfc_check_rename (gfc_expr
*path1
, gfc_expr
*path2
)
3081 if (type_check (path1
, 0, BT_CHARACTER
) == FAILURE
)
3083 if (kind_value_check (path1
, 0, gfc_default_character_kind
) == FAILURE
)
3086 if (type_check (path2
, 1, BT_CHARACTER
) == FAILURE
)
3088 if (kind_value_check (path2
, 1, gfc_default_character_kind
) == FAILURE
)
3096 gfc_check_rename_sub (gfc_expr
*path1
, gfc_expr
*path2
, gfc_expr
*status
)
3098 if (type_check (path1
, 0, BT_CHARACTER
) == FAILURE
)
3100 if (kind_value_check (path1
, 0, gfc_default_character_kind
) == FAILURE
)
3103 if (type_check (path2
, 1, BT_CHARACTER
) == FAILURE
)
3105 if (kind_value_check (path2
, 1, gfc_default_character_kind
) == FAILURE
)
3111 if (type_check (status
, 2, BT_INTEGER
) == FAILURE
)
3114 if (scalar_check (status
, 2) == FAILURE
)
3122 gfc_check_repeat (gfc_expr
*x
, gfc_expr
*y
)
3124 if (type_check (x
, 0, BT_CHARACTER
) == FAILURE
)
3127 if (scalar_check (x
, 0) == FAILURE
)
3130 if (type_check (y
, 0, BT_INTEGER
) == FAILURE
)
3133 if (scalar_check (y
, 1) == FAILURE
)
3141 gfc_check_reshape (gfc_expr
*source
, gfc_expr
*shape
,
3142 gfc_expr
*pad
, gfc_expr
*order
)
3148 if (array_check (source
, 0) == FAILURE
)
3151 if (rank_check (shape
, 1, 1) == FAILURE
)
3154 if (type_check (shape
, 1, BT_INTEGER
) == FAILURE
)
3157 if (gfc_array_size (shape
, &size
) != SUCCESS
)
3159 gfc_error ("'shape' argument of 'reshape' intrinsic at %L must be an "
3160 "array of constant size", &shape
->where
);
3164 shape_size
= mpz_get_ui (size
);
3167 if (shape_size
<= 0)
3169 gfc_error ("'%s' argument of '%s' intrinsic at %L is empty",
3170 gfc_current_intrinsic_arg
[1]->name
, gfc_current_intrinsic
,
3174 else if (shape_size
> GFC_MAX_DIMENSIONS
)
3176 gfc_error ("'shape' argument of 'reshape' intrinsic at %L has more "
3177 "than %d elements", &shape
->where
, GFC_MAX_DIMENSIONS
);
3180 else if (shape
->expr_type
== EXPR_ARRAY
)
3184 for (i
= 0; i
< shape_size
; ++i
)
3186 e
= gfc_constructor_lookup_expr (shape
->value
.constructor
, i
);
3187 if (e
->expr_type
!= EXPR_CONSTANT
)
3190 gfc_extract_int (e
, &extent
);
3193 gfc_error ("'%s' argument of '%s' intrinsic at %L has "
3194 "negative element (%d)",
3195 gfc_current_intrinsic_arg
[1]->name
,
3196 gfc_current_intrinsic
, &e
->where
, extent
);
3204 if (same_type_check (source
, 0, pad
, 2) == FAILURE
)
3207 if (array_check (pad
, 2) == FAILURE
)
3213 if (array_check (order
, 3) == FAILURE
)
3216 if (type_check (order
, 3, BT_INTEGER
) == FAILURE
)
3219 if (order
->expr_type
== EXPR_ARRAY
)
3221 int i
, order_size
, dim
, perm
[GFC_MAX_DIMENSIONS
];
3224 for (i
= 0; i
< GFC_MAX_DIMENSIONS
; ++i
)
3227 gfc_array_size (order
, &size
);
3228 order_size
= mpz_get_ui (size
);
3231 if (order_size
!= shape_size
)
3233 gfc_error ("'%s' argument of '%s' intrinsic at %L "
3234 "has wrong number of elements (%d/%d)",
3235 gfc_current_intrinsic_arg
[3]->name
,
3236 gfc_current_intrinsic
, &order
->where
,
3237 order_size
, shape_size
);
3241 for (i
= 1; i
<= order_size
; ++i
)
3243 e
= gfc_constructor_lookup_expr (order
->value
.constructor
, i
-1);
3244 if (e
->expr_type
!= EXPR_CONSTANT
)
3247 gfc_extract_int (e
, &dim
);
3249 if (dim
< 1 || dim
> order_size
)
3251 gfc_error ("'%s' argument of '%s' intrinsic at %L "
3252 "has out-of-range dimension (%d)",
3253 gfc_current_intrinsic_arg
[3]->name
,
3254 gfc_current_intrinsic
, &e
->where
, dim
);
3258 if (perm
[dim
-1] != 0)
3260 gfc_error ("'%s' argument of '%s' intrinsic at %L has "
3261 "invalid permutation of dimensions (dimension "
3263 gfc_current_intrinsic_arg
[3]->name
,
3264 gfc_current_intrinsic
, &e
->where
, dim
);
3273 if (pad
== NULL
&& shape
->expr_type
== EXPR_ARRAY
3274 && gfc_is_constant_expr (shape
)
3275 && !(source
->expr_type
== EXPR_VARIABLE
&& source
->symtree
->n
.sym
->as
3276 && source
->symtree
->n
.sym
->as
->type
== AS_ASSUMED_SIZE
))
3278 /* Check the match in size between source and destination. */
3279 if (gfc_array_size (source
, &nelems
) == SUCCESS
)
3285 mpz_init_set_ui (size
, 1);
3286 for (c
= gfc_constructor_first (shape
->value
.constructor
);
3287 c
; c
= gfc_constructor_next (c
))
3288 mpz_mul (size
, size
, c
->expr
->value
.integer
);
3290 test
= mpz_cmp (nelems
, size
) < 0 && mpz_cmp_ui (size
, 0) > 0;
3296 gfc_error ("Without padding, there are not enough elements "
3297 "in the intrinsic RESHAPE source at %L to match "
3298 "the shape", &source
->where
);
3309 gfc_check_same_type_as (gfc_expr
*a
, gfc_expr
*b
)
3312 if (a
->ts
.type
!= BT_DERIVED
&& a
->ts
.type
!= BT_CLASS
)
3314 gfc_error ("'%s' argument of '%s' intrinsic at %L "
3315 "must be of a derived type",
3316 gfc_current_intrinsic_arg
[0]->name
, gfc_current_intrinsic
,
3321 if (!gfc_type_is_extensible (a
->ts
.u
.derived
))
3323 gfc_error ("'%s' argument of '%s' intrinsic at %L "
3324 "must be of an extensible type",
3325 gfc_current_intrinsic_arg
[0]->name
, gfc_current_intrinsic
,
3330 if (b
->ts
.type
!= BT_DERIVED
&& b
->ts
.type
!= BT_CLASS
)
3332 gfc_error ("'%s' argument of '%s' intrinsic at %L "
3333 "must be of a derived type",
3334 gfc_current_intrinsic_arg
[1]->name
, gfc_current_intrinsic
,
3339 if (!gfc_type_is_extensible (b
->ts
.u
.derived
))
3341 gfc_error ("'%s' argument of '%s' intrinsic at %L "
3342 "must be of an extensible type",
3343 gfc_current_intrinsic_arg
[1]->name
, gfc_current_intrinsic
,
3353 gfc_check_scale (gfc_expr
*x
, gfc_expr
*i
)
3355 if (type_check (x
, 0, BT_REAL
) == FAILURE
)
3358 if (type_check (i
, 1, BT_INTEGER
) == FAILURE
)
3366 gfc_check_scan (gfc_expr
*x
, gfc_expr
*y
, gfc_expr
*z
, gfc_expr
*kind
)
3368 if (type_check (x
, 0, BT_CHARACTER
) == FAILURE
)
3371 if (type_check (y
, 1, BT_CHARACTER
) == FAILURE
)
3374 if (z
!= NULL
&& type_check (z
, 2, BT_LOGICAL
) == FAILURE
)
3377 if (kind_check (kind
, 3, BT_INTEGER
) == FAILURE
)
3379 if (kind
&& gfc_notify_std (GFC_STD_F2003
, "Fortran 2003: '%s' intrinsic "
3380 "with KIND argument at %L",
3381 gfc_current_intrinsic
, &kind
->where
) == FAILURE
)
3384 if (same_type_check (x
, 0, y
, 1) == FAILURE
)
3392 gfc_check_secnds (gfc_expr
*r
)
3394 if (type_check (r
, 0, BT_REAL
) == FAILURE
)
3397 if (kind_value_check (r
, 0, 4) == FAILURE
)
3400 if (scalar_check (r
, 0) == FAILURE
)
3408 gfc_check_selected_char_kind (gfc_expr
*name
)
3410 if (type_check (name
, 0, BT_CHARACTER
) == FAILURE
)
3413 if (kind_value_check (name
, 0, gfc_default_character_kind
) == FAILURE
)
3416 if (scalar_check (name
, 0) == FAILURE
)
3424 gfc_check_selected_int_kind (gfc_expr
*r
)
3426 if (type_check (r
, 0, BT_INTEGER
) == FAILURE
)
3429 if (scalar_check (r
, 0) == FAILURE
)
3437 gfc_check_selected_real_kind (gfc_expr
*p
, gfc_expr
*r
, gfc_expr
*radix
)
3439 if (p
== NULL
&& r
== NULL
3440 && gfc_notify_std (GFC_STD_F2008
, "Fortran 2008: SELECTED_REAL_KIND with"
3441 " neither 'P' nor 'R' argument at %L",
3442 gfc_current_intrinsic_where
) == FAILURE
)
3447 if (type_check (p
, 0, BT_INTEGER
) == FAILURE
)
3450 if (scalar_check (p
, 0) == FAILURE
)
3456 if (type_check (r
, 1, BT_INTEGER
) == FAILURE
)
3459 if (scalar_check (r
, 1) == FAILURE
)
3465 if (type_check (radix
, 1, BT_INTEGER
) == FAILURE
)
3468 if (scalar_check (radix
, 1) == FAILURE
)
3471 if (gfc_notify_std (GFC_STD_F2008
, "Fortran 2008: '%s' intrinsic with "
3472 "RADIX argument at %L", gfc_current_intrinsic
,
3473 &radix
->where
) == FAILURE
)
3482 gfc_check_set_exponent (gfc_expr
*x
, gfc_expr
*i
)
3484 if (type_check (x
, 0, BT_REAL
) == FAILURE
)
3487 if (type_check (i
, 1, BT_INTEGER
) == FAILURE
)
3495 gfc_check_shape (gfc_expr
*source
, gfc_expr
*kind
)
3499 if (source
->rank
== 0 || source
->expr_type
!= EXPR_VARIABLE
)
3502 ar
= gfc_find_array_ref (source
);
3504 if (ar
->as
&& ar
->as
->type
== AS_ASSUMED_SIZE
&& ar
->type
== AR_FULL
)
3506 gfc_error ("'source' argument of 'shape' intrinsic at %L must not be "
3507 "an assumed size array", &source
->where
);
3511 if (kind_check (kind
, 1, BT_INTEGER
) == FAILURE
)
3513 if (kind
&& gfc_notify_std (GFC_STD_F2003
, "Fortran 2003: '%s' intrinsic "
3514 "with KIND argument at %L",
3515 gfc_current_intrinsic
, &kind
->where
) == FAILURE
)
3523 gfc_check_shift (gfc_expr
*i
, gfc_expr
*shift
)
3525 if (type_check (i
, 0, BT_INTEGER
) == FAILURE
)
3528 if (type_check (shift
, 0, BT_INTEGER
) == FAILURE
)
3531 if (nonnegative_check ("SHIFT", shift
) == FAILURE
)
3534 if (less_than_bitsize1 ("I", i
, "SHIFT", shift
, true) == FAILURE
)
3542 gfc_check_sign (gfc_expr
*a
, gfc_expr
*b
)
3544 if (int_or_real_check (a
, 0) == FAILURE
)
3547 if (same_type_check (a
, 0, b
, 1) == FAILURE
)
3555 gfc_check_size (gfc_expr
*array
, gfc_expr
*dim
, gfc_expr
*kind
)
3557 if (array_check (array
, 0) == FAILURE
)
3560 if (dim_check (dim
, 1, true) == FAILURE
)
3563 if (dim_rank_check (dim
, array
, 0) == FAILURE
)
3566 if (kind_check (kind
, 2, BT_INTEGER
) == FAILURE
)
3568 if (kind
&& gfc_notify_std (GFC_STD_F2003
, "Fortran 2003: '%s' intrinsic "
3569 "with KIND argument at %L",
3570 gfc_current_intrinsic
, &kind
->where
) == FAILURE
)
3579 gfc_check_sizeof (gfc_expr
*arg
)
3581 if (arg
->ts
.type
== BT_PROCEDURE
)
3583 gfc_error ("'%s' argument of '%s' intrinsic at %L may not be a procedure",
3584 gfc_current_intrinsic_arg
[0]->name
, gfc_current_intrinsic
,
3593 gfc_check_c_sizeof (gfc_expr
*arg
)
3595 if (gfc_verify_c_interop (&arg
->ts
) != SUCCESS
)
3597 gfc_error ("'%s' argument of '%s' intrinsic at %L must be an "
3598 "interoperable data entity",
3599 gfc_current_intrinsic_arg
[0]->name
, gfc_current_intrinsic
,
3608 gfc_check_sleep_sub (gfc_expr
*seconds
)
3610 if (type_check (seconds
, 0, BT_INTEGER
) == FAILURE
)
3613 if (scalar_check (seconds
, 0) == FAILURE
)
3620 gfc_check_sngl (gfc_expr
*a
)
3622 if (type_check (a
, 0, BT_REAL
) == FAILURE
)
3625 if ((a
->ts
.kind
!= gfc_default_double_kind
)
3626 && gfc_notify_std (GFC_STD_GNU
, "GNU extension: non double precision "
3627 "REAL argument to %s intrinsic at %L",
3628 gfc_current_intrinsic
, &a
->where
) == FAILURE
)
3635 gfc_check_spread (gfc_expr
*source
, gfc_expr
*dim
, gfc_expr
*ncopies
)
3637 if (source
->rank
>= GFC_MAX_DIMENSIONS
)
3639 gfc_error ("'%s' argument of '%s' intrinsic at %L must be less "
3640 "than rank %d", gfc_current_intrinsic_arg
[0]->name
,
3641 gfc_current_intrinsic
, &source
->where
, GFC_MAX_DIMENSIONS
);
3649 if (dim_check (dim
, 1, false) == FAILURE
)
3652 /* dim_rank_check() does not apply here. */
3654 && dim
->expr_type
== EXPR_CONSTANT
3655 && (mpz_cmp_ui (dim
->value
.integer
, 1) < 0
3656 || mpz_cmp_ui (dim
->value
.integer
, source
->rank
+ 1) > 0))
3658 gfc_error ("'%s' argument of '%s' intrinsic at %L is not a valid "
3659 "dimension index", gfc_current_intrinsic_arg
[1]->name
,
3660 gfc_current_intrinsic
, &dim
->where
);
3664 if (type_check (ncopies
, 2, BT_INTEGER
) == FAILURE
)
3667 if (scalar_check (ncopies
, 2) == FAILURE
)
3674 /* Functions for checking FGETC, FPUTC, FGET and FPUT (subroutines and
3678 gfc_check_fgetputc_sub (gfc_expr
*unit
, gfc_expr
*c
, gfc_expr
*status
)
3680 if (type_check (unit
, 0, BT_INTEGER
) == FAILURE
)
3683 if (scalar_check (unit
, 0) == FAILURE
)
3686 if (type_check (c
, 1, BT_CHARACTER
) == FAILURE
)
3688 if (kind_value_check (c
, 1, gfc_default_character_kind
) == FAILURE
)
3694 if (type_check (status
, 2, BT_INTEGER
) == FAILURE
3695 || kind_value_check (status
, 2, gfc_default_integer_kind
) == FAILURE
3696 || scalar_check (status
, 2) == FAILURE
)
3704 gfc_check_fgetputc (gfc_expr
*unit
, gfc_expr
*c
)
3706 return gfc_check_fgetputc_sub (unit
, c
, NULL
);
3711 gfc_check_fgetput_sub (gfc_expr
*c
, gfc_expr
*status
)
3713 if (type_check (c
, 0, BT_CHARACTER
) == FAILURE
)
3715 if (kind_value_check (c
, 0, gfc_default_character_kind
) == FAILURE
)
3721 if (type_check (status
, 1, BT_INTEGER
) == FAILURE
3722 || kind_value_check (status
, 1, gfc_default_integer_kind
) == FAILURE
3723 || scalar_check (status
, 1) == FAILURE
)
3731 gfc_check_fgetput (gfc_expr
*c
)
3733 return gfc_check_fgetput_sub (c
, NULL
);
3738 gfc_check_fseek_sub (gfc_expr
*unit
, gfc_expr
*offset
, gfc_expr
*whence
, gfc_expr
*status
)
3740 if (type_check (unit
, 0, BT_INTEGER
) == FAILURE
)
3743 if (scalar_check (unit
, 0) == FAILURE
)
3746 if (type_check (offset
, 1, BT_INTEGER
) == FAILURE
)
3749 if (scalar_check (offset
, 1) == FAILURE
)
3752 if (type_check (whence
, 2, BT_INTEGER
) == FAILURE
)
3755 if (scalar_check (whence
, 2) == FAILURE
)
3761 if (type_check (status
, 3, BT_INTEGER
) == FAILURE
)
3764 if (kind_value_check (status
, 3, 4) == FAILURE
)
3767 if (scalar_check (status
, 3) == FAILURE
)
3776 gfc_check_fstat (gfc_expr
*unit
, gfc_expr
*array
)
3778 if (type_check (unit
, 0, BT_INTEGER
) == FAILURE
)
3781 if (scalar_check (unit
, 0) == FAILURE
)
3784 if (type_check (array
, 1, BT_INTEGER
) == FAILURE
3785 || kind_value_check (unit
, 0, gfc_default_integer_kind
) == FAILURE
)
3788 if (array_check (array
, 1) == FAILURE
)
3796 gfc_check_fstat_sub (gfc_expr
*unit
, gfc_expr
*array
, gfc_expr
*status
)
3798 if (type_check (unit
, 0, BT_INTEGER
) == FAILURE
)
3801 if (scalar_check (unit
, 0) == FAILURE
)
3804 if (type_check (array
, 1, BT_INTEGER
) == FAILURE
3805 || kind_value_check (array
, 1, gfc_default_integer_kind
) == FAILURE
)
3808 if (array_check (array
, 1) == FAILURE
)
3814 if (type_check (status
, 2, BT_INTEGER
) == FAILURE
3815 || kind_value_check (status
, 2, gfc_default_integer_kind
) == FAILURE
)
3818 if (scalar_check (status
, 2) == FAILURE
)
3826 gfc_check_ftell (gfc_expr
*unit
)
3828 if (type_check (unit
, 0, BT_INTEGER
) == FAILURE
)
3831 if (scalar_check (unit
, 0) == FAILURE
)
3839 gfc_check_ftell_sub (gfc_expr
*unit
, gfc_expr
*offset
)
3841 if (type_check (unit
, 0, BT_INTEGER
) == FAILURE
)
3844 if (scalar_check (unit
, 0) == FAILURE
)
3847 if (type_check (offset
, 1, BT_INTEGER
) == FAILURE
)
3850 if (scalar_check (offset
, 1) == FAILURE
)
3858 gfc_check_stat (gfc_expr
*name
, gfc_expr
*array
)
3860 if (type_check (name
, 0, BT_CHARACTER
) == FAILURE
)
3862 if (kind_value_check (name
, 0, gfc_default_character_kind
) == FAILURE
)
3865 if (type_check (array
, 1, BT_INTEGER
) == FAILURE
3866 || kind_value_check (array
, 1, gfc_default_integer_kind
) == FAILURE
)
3869 if (array_check (array
, 1) == FAILURE
)
3877 gfc_check_stat_sub (gfc_expr
*name
, gfc_expr
*array
, gfc_expr
*status
)
3879 if (type_check (name
, 0, BT_CHARACTER
) == FAILURE
)
3881 if (kind_value_check (name
, 0, gfc_default_character_kind
) == FAILURE
)
3884 if (type_check (array
, 1, BT_INTEGER
) == FAILURE
3885 || kind_value_check (array
, 1, gfc_default_integer_kind
) == FAILURE
)
3888 if (array_check (array
, 1) == FAILURE
)
3894 if (type_check (status
, 2, BT_INTEGER
) == FAILURE
3895 || kind_value_check (array
, 1, gfc_default_integer_kind
) == FAILURE
)
3898 if (scalar_check (status
, 2) == FAILURE
)
3906 gfc_check_image_index (gfc_expr
*coarray
, gfc_expr
*sub
)
3910 if (gfc_option
.coarray
== GFC_FCOARRAY_NONE
)
3912 gfc_fatal_error ("Coarrays disabled at %C, use -fcoarray= to enable");
3916 if (coarray_check (coarray
, 0) == FAILURE
)
3921 gfc_error ("%s argument to IMAGE_INDEX must be a rank one array at %L",
3922 gfc_current_intrinsic_arg
[1]->name
, &sub
->where
);
3926 if (gfc_array_size (sub
, &nelems
) == SUCCESS
)
3928 int corank
= gfc_get_corank (coarray
);
3930 if (mpz_cmp_ui (nelems
, corank
) != 0)
3932 gfc_error ("The number of array elements of the SUB argument to "
3933 "IMAGE_INDEX at %L shall be %d (corank) not %d",
3934 &sub
->where
, corank
, (int) mpz_get_si (nelems
));
3946 gfc_check_this_image (gfc_expr
*coarray
, gfc_expr
*dim
)
3948 if (gfc_option
.coarray
== GFC_FCOARRAY_NONE
)
3950 gfc_fatal_error ("Coarrays disabled at %C, use -fcoarray= to enable");
3954 if (dim
!= NULL
&& coarray
== NULL
)
3956 gfc_error ("DIM argument without ARRAY argument not allowed for THIS_IMAGE "
3957 "intrinsic at %L", &dim
->where
);
3961 if (coarray
== NULL
)
3964 if (coarray_check (coarray
, 0) == FAILURE
)
3969 if (dim_check (dim
, 1, false) == FAILURE
)
3972 if (dim_corank_check (dim
, coarray
) == FAILURE
)
3979 /* Calculate the sizes for transfer, used by gfc_check_transfer and also
3980 by gfc_simplify_transfer. Return FAILURE if we cannot do so. */
3983 gfc_calculate_transfer_sizes (gfc_expr
*source
, gfc_expr
*mold
, gfc_expr
*size
,
3984 size_t *source_size
, size_t *result_size
,
3985 size_t *result_length_p
)
3988 size_t result_elt_size
;
3990 gfc_expr
*mold_element
;
3992 if (source
->expr_type
== EXPR_FUNCTION
)
3995 /* Calculate the size of the source. */
3996 if (source
->expr_type
== EXPR_ARRAY
3997 && gfc_array_size (source
, &tmp
) == FAILURE
)
4000 *source_size
= gfc_target_expr_size (source
);
4002 mold_element
= mold
->expr_type
== EXPR_ARRAY
4003 ? gfc_constructor_first (mold
->value
.constructor
)->expr
4006 /* Determine the size of the element. */
4007 result_elt_size
= gfc_target_expr_size (mold_element
);
4008 if (result_elt_size
== 0)
4011 if (mold
->expr_type
== EXPR_ARRAY
|| mold
->rank
|| size
)
4016 result_length
= (size_t)mpz_get_ui (size
->value
.integer
);
4019 result_length
= *source_size
/ result_elt_size
;
4020 if (result_length
* result_elt_size
< *source_size
)
4024 *result_size
= result_length
* result_elt_size
;
4025 if (result_length_p
)
4026 *result_length_p
= result_length
;
4029 *result_size
= result_elt_size
;
4036 gfc_check_transfer (gfc_expr
*source
, gfc_expr
*mold
, gfc_expr
*size
)
4041 if (mold
->ts
.type
== BT_HOLLERITH
)
4043 gfc_error ("'MOLD' argument of 'TRANSFER' intrinsic at %L must not be %s",
4044 &mold
->where
, gfc_basic_typename (BT_HOLLERITH
));
4050 if (type_check (size
, 2, BT_INTEGER
) == FAILURE
)
4053 if (scalar_check (size
, 2) == FAILURE
)
4056 if (nonoptional_check (size
, 2) == FAILURE
)
4060 if (!gfc_option
.warn_surprising
)
4063 /* If we can't calculate the sizes, we cannot check any more.
4064 Return SUCCESS for that case. */
4066 if (gfc_calculate_transfer_sizes (source
, mold
, size
, &source_size
,
4067 &result_size
, NULL
) == FAILURE
)
4070 if (source_size
< result_size
)
4071 gfc_warning("Intrinsic TRANSFER at %L has partly undefined result: "
4072 "source size %ld < result size %ld", &source
->where
,
4073 (long) source_size
, (long) result_size
);
4080 gfc_check_transpose (gfc_expr
*matrix
)
4082 if (rank_check (matrix
, 0, 2) == FAILURE
)
4090 gfc_check_ubound (gfc_expr
*array
, gfc_expr
*dim
, gfc_expr
*kind
)
4092 if (array_check (array
, 0) == FAILURE
)
4095 if (dim_check (dim
, 1, false) == FAILURE
)
4098 if (dim_rank_check (dim
, array
, 0) == FAILURE
)
4101 if (kind_check (kind
, 2, BT_INTEGER
) == FAILURE
)
4103 if (kind
&& gfc_notify_std (GFC_STD_F2003
, "Fortran 2003: '%s' intrinsic "
4104 "with KIND argument at %L",
4105 gfc_current_intrinsic
, &kind
->where
) == FAILURE
)
4113 gfc_check_ucobound (gfc_expr
*coarray
, gfc_expr
*dim
, gfc_expr
*kind
)
4115 if (gfc_option
.coarray
== GFC_FCOARRAY_NONE
)
4117 gfc_fatal_error ("Coarrays disabled at %C, use -fcoarray= to enable");
4121 if (coarray_check (coarray
, 0) == FAILURE
)
4126 if (dim_check (dim
, 1, false) == FAILURE
)
4129 if (dim_corank_check (dim
, coarray
) == FAILURE
)
4133 if (kind_check (kind
, 2, BT_INTEGER
) == FAILURE
)
4141 gfc_check_unpack (gfc_expr
*vector
, gfc_expr
*mask
, gfc_expr
*field
)
4145 if (rank_check (vector
, 0, 1) == FAILURE
)
4148 if (array_check (mask
, 1) == FAILURE
)
4151 if (type_check (mask
, 1, BT_LOGICAL
) == FAILURE
)
4154 if (same_type_check (vector
, 0, field
, 2) == FAILURE
)
4157 if (mask
->expr_type
== EXPR_ARRAY
4158 && gfc_array_size (vector
, &vector_size
) == SUCCESS
)
4160 int mask_true_count
= 0;
4161 gfc_constructor
*mask_ctor
;
4162 mask_ctor
= gfc_constructor_first (mask
->value
.constructor
);
4165 if (mask_ctor
->expr
->expr_type
!= EXPR_CONSTANT
)
4167 mask_true_count
= 0;
4171 if (mask_ctor
->expr
->value
.logical
)
4174 mask_ctor
= gfc_constructor_next (mask_ctor
);
4177 if (mpz_get_si (vector_size
) < mask_true_count
)
4179 gfc_error ("'%s' argument of '%s' intrinsic at %L must "
4180 "provide at least as many elements as there "
4181 "are .TRUE. values in '%s' (%ld/%d)",
4182 gfc_current_intrinsic_arg
[0]->name
, gfc_current_intrinsic
,
4183 &vector
->where
, gfc_current_intrinsic_arg
[1]->name
,
4184 mpz_get_si (vector_size
), mask_true_count
);
4188 mpz_clear (vector_size
);
4191 if (mask
->rank
!= field
->rank
&& field
->rank
!= 0)
4193 gfc_error ("'%s' argument of '%s' intrinsic at %L must have "
4194 "the same rank as '%s' or be a scalar",
4195 gfc_current_intrinsic_arg
[2]->name
, gfc_current_intrinsic
,
4196 &field
->where
, gfc_current_intrinsic_arg
[1]->name
);
4200 if (mask
->rank
== field
->rank
)
4203 for (i
= 0; i
< field
->rank
; i
++)
4204 if (! identical_dimen_shape (mask
, i
, field
, i
))
4206 gfc_error ("'%s' and '%s' arguments of '%s' intrinsic at %L "
4207 "must have identical shape.",
4208 gfc_current_intrinsic_arg
[2]->name
,
4209 gfc_current_intrinsic_arg
[1]->name
, gfc_current_intrinsic
,
4219 gfc_check_verify (gfc_expr
*x
, gfc_expr
*y
, gfc_expr
*z
, gfc_expr
*kind
)
4221 if (type_check (x
, 0, BT_CHARACTER
) == FAILURE
)
4224 if (same_type_check (x
, 0, y
, 1) == FAILURE
)
4227 if (z
!= NULL
&& type_check (z
, 2, BT_LOGICAL
) == FAILURE
)
4230 if (kind_check (kind
, 3, BT_INTEGER
) == FAILURE
)
4232 if (kind
&& gfc_notify_std (GFC_STD_F2003
, "Fortran 2003: '%s' intrinsic "
4233 "with KIND argument at %L",
4234 gfc_current_intrinsic
, &kind
->where
) == FAILURE
)
4242 gfc_check_trim (gfc_expr
*x
)
4244 if (type_check (x
, 0, BT_CHARACTER
) == FAILURE
)
4247 if (scalar_check (x
, 0) == FAILURE
)
4255 gfc_check_ttynam (gfc_expr
*unit
)
4257 if (scalar_check (unit
, 0) == FAILURE
)
4260 if (type_check (unit
, 0, BT_INTEGER
) == FAILURE
)
4267 /* Common check function for the half a dozen intrinsics that have a
4268 single real argument. */
4271 gfc_check_x (gfc_expr
*x
)
4273 if (type_check (x
, 0, BT_REAL
) == FAILURE
)
4280 /************* Check functions for intrinsic subroutines *************/
4283 gfc_check_cpu_time (gfc_expr
*time
)
4285 if (scalar_check (time
, 0) == FAILURE
)
4288 if (type_check (time
, 0, BT_REAL
) == FAILURE
)
4291 if (variable_check (time
, 0, false) == FAILURE
)
4299 gfc_check_date_and_time (gfc_expr
*date
, gfc_expr
*time
,
4300 gfc_expr
*zone
, gfc_expr
*values
)
4304 if (type_check (date
, 0, BT_CHARACTER
) == FAILURE
)
4306 if (kind_value_check (date
, 0, gfc_default_character_kind
) == FAILURE
)
4308 if (scalar_check (date
, 0) == FAILURE
)
4310 if (variable_check (date
, 0, false) == FAILURE
)
4316 if (type_check (time
, 1, BT_CHARACTER
) == FAILURE
)
4318 if (kind_value_check (time
, 1, gfc_default_character_kind
) == FAILURE
)
4320 if (scalar_check (time
, 1) == FAILURE
)
4322 if (variable_check (time
, 1, false) == FAILURE
)
4328 if (type_check (zone
, 2, BT_CHARACTER
) == FAILURE
)
4330 if (kind_value_check (zone
, 2, gfc_default_character_kind
) == FAILURE
)
4332 if (scalar_check (zone
, 2) == FAILURE
)
4334 if (variable_check (zone
, 2, false) == FAILURE
)
4340 if (type_check (values
, 3, BT_INTEGER
) == FAILURE
)
4342 if (array_check (values
, 3) == FAILURE
)
4344 if (rank_check (values
, 3, 1) == FAILURE
)
4346 if (variable_check (values
, 3, false) == FAILURE
)
4355 gfc_check_mvbits (gfc_expr
*from
, gfc_expr
*frompos
, gfc_expr
*len
,
4356 gfc_expr
*to
, gfc_expr
*topos
)
4358 if (type_check (from
, 0, BT_INTEGER
) == FAILURE
)
4361 if (type_check (frompos
, 1, BT_INTEGER
) == FAILURE
)
4364 if (type_check (len
, 2, BT_INTEGER
) == FAILURE
)
4367 if (same_type_check (from
, 0, to
, 3) == FAILURE
)
4370 if (variable_check (to
, 3, false) == FAILURE
)
4373 if (type_check (topos
, 4, BT_INTEGER
) == FAILURE
)
4376 if (nonnegative_check ("frompos", frompos
) == FAILURE
)
4379 if (nonnegative_check ("topos", topos
) == FAILURE
)
4382 if (nonnegative_check ("len", len
) == FAILURE
)
4385 if (less_than_bitsize2 ("from", from
, "frompos", frompos
, "len", len
)
4389 if (less_than_bitsize2 ("to", to
, "topos", topos
, "len", len
) == FAILURE
)
4397 gfc_check_random_number (gfc_expr
*harvest
)
4399 if (type_check (harvest
, 0, BT_REAL
) == FAILURE
)
4402 if (variable_check (harvest
, 0, false) == FAILURE
)
4410 gfc_check_random_seed (gfc_expr
*size
, gfc_expr
*put
, gfc_expr
*get
)
4412 unsigned int nargs
= 0, kiss_size
;
4413 locus
*where
= NULL
;
4414 mpz_t put_size
, get_size
;
4415 bool have_gfc_real_16
; /* Try and mimic HAVE_GFC_REAL_16 in libgfortran. */
4417 have_gfc_real_16
= gfc_validate_kind (BT_REAL
, 16, true) != -1;
4419 /* Keep the number of bytes in sync with kiss_size in
4420 libgfortran/intrinsics/random.c. */
4421 kiss_size
= (have_gfc_real_16
? 48 : 32) / gfc_default_integer_kind
;
4425 if (size
->expr_type
!= EXPR_VARIABLE
4426 || !size
->symtree
->n
.sym
->attr
.optional
)
4429 if (scalar_check (size
, 0) == FAILURE
)
4432 if (type_check (size
, 0, BT_INTEGER
) == FAILURE
)
4435 if (variable_check (size
, 0, false) == FAILURE
)
4438 if (kind_value_check (size
, 0, gfc_default_integer_kind
) == FAILURE
)
4444 if (put
->expr_type
!= EXPR_VARIABLE
4445 || !put
->symtree
->n
.sym
->attr
.optional
)
4448 where
= &put
->where
;
4451 if (array_check (put
, 1) == FAILURE
)
4454 if (rank_check (put
, 1, 1) == FAILURE
)
4457 if (type_check (put
, 1, BT_INTEGER
) == FAILURE
)
4460 if (kind_value_check (put
, 1, gfc_default_integer_kind
) == FAILURE
)
4463 if (gfc_array_size (put
, &put_size
) == SUCCESS
4464 && mpz_get_ui (put_size
) < kiss_size
)
4465 gfc_error ("Size of '%s' argument of '%s' intrinsic at %L "
4466 "too small (%i/%i)",
4467 gfc_current_intrinsic_arg
[1]->name
, gfc_current_intrinsic
,
4468 where
, (int) mpz_get_ui (put_size
), kiss_size
);
4473 if (get
->expr_type
!= EXPR_VARIABLE
4474 || !get
->symtree
->n
.sym
->attr
.optional
)
4477 where
= &get
->where
;
4480 if (array_check (get
, 2) == FAILURE
)
4483 if (rank_check (get
, 2, 1) == FAILURE
)
4486 if (type_check (get
, 2, BT_INTEGER
) == FAILURE
)
4489 if (variable_check (get
, 2, false) == FAILURE
)
4492 if (kind_value_check (get
, 2, gfc_default_integer_kind
) == FAILURE
)
4495 if (gfc_array_size (get
, &get_size
) == SUCCESS
4496 && mpz_get_ui (get_size
) < kiss_size
)
4497 gfc_error ("Size of '%s' argument of '%s' intrinsic at %L "
4498 "too small (%i/%i)",
4499 gfc_current_intrinsic_arg
[2]->name
, gfc_current_intrinsic
,
4500 where
, (int) mpz_get_ui (get_size
), kiss_size
);
4503 /* RANDOM_SEED may not have more than one non-optional argument. */
4505 gfc_error ("Too many arguments to %s at %L", gfc_current_intrinsic
, where
);
4512 gfc_check_second_sub (gfc_expr
*time
)
4514 if (scalar_check (time
, 0) == FAILURE
)
4517 if (type_check (time
, 0, BT_REAL
) == FAILURE
)
4520 if (kind_value_check(time
, 0, 4) == FAILURE
)
4527 /* The arguments of SYSTEM_CLOCK are scalar, integer variables. Note,
4528 count, count_rate, and count_max are all optional arguments */
4531 gfc_check_system_clock (gfc_expr
*count
, gfc_expr
*count_rate
,
4532 gfc_expr
*count_max
)
4536 if (scalar_check (count
, 0) == FAILURE
)
4539 if (type_check (count
, 0, BT_INTEGER
) == FAILURE
)
4542 if (variable_check (count
, 0, false) == FAILURE
)
4546 if (count_rate
!= NULL
)
4548 if (scalar_check (count_rate
, 1) == FAILURE
)
4551 if (type_check (count_rate
, 1, BT_INTEGER
) == FAILURE
)
4554 if (variable_check (count_rate
, 1, false) == FAILURE
)
4558 && same_type_check (count
, 0, count_rate
, 1) == FAILURE
)
4563 if (count_max
!= NULL
)
4565 if (scalar_check (count_max
, 2) == FAILURE
)
4568 if (type_check (count_max
, 2, BT_INTEGER
) == FAILURE
)
4571 if (variable_check (count_max
, 2, false) == FAILURE
)
4575 && same_type_check (count
, 0, count_max
, 2) == FAILURE
)
4578 if (count_rate
!= NULL
4579 && same_type_check (count_rate
, 1, count_max
, 2) == FAILURE
)
4588 gfc_check_irand (gfc_expr
*x
)
4593 if (scalar_check (x
, 0) == FAILURE
)
4596 if (type_check (x
, 0, BT_INTEGER
) == FAILURE
)
4599 if (kind_value_check(x
, 0, 4) == FAILURE
)
4607 gfc_check_alarm_sub (gfc_expr
*seconds
, gfc_expr
*handler
, gfc_expr
*status
)
4609 if (scalar_check (seconds
, 0) == FAILURE
)
4611 if (type_check (seconds
, 0, BT_INTEGER
) == FAILURE
)
4614 if (int_or_proc_check (handler
, 1) == FAILURE
)
4616 if (handler
->ts
.type
== BT_INTEGER
&& scalar_check (handler
, 1) == FAILURE
)
4622 if (scalar_check (status
, 2) == FAILURE
)
4624 if (type_check (status
, 2, BT_INTEGER
) == FAILURE
)
4626 if (kind_value_check (status
, 2, gfc_default_integer_kind
) == FAILURE
)
4634 gfc_check_rand (gfc_expr
*x
)
4639 if (scalar_check (x
, 0) == FAILURE
)
4642 if (type_check (x
, 0, BT_INTEGER
) == FAILURE
)
4645 if (kind_value_check(x
, 0, 4) == FAILURE
)
4653 gfc_check_srand (gfc_expr
*x
)
4655 if (scalar_check (x
, 0) == FAILURE
)
4658 if (type_check (x
, 0, BT_INTEGER
) == FAILURE
)
4661 if (kind_value_check(x
, 0, 4) == FAILURE
)
4669 gfc_check_ctime_sub (gfc_expr
*time
, gfc_expr
*result
)
4671 if (scalar_check (time
, 0) == FAILURE
)
4673 if (type_check (time
, 0, BT_INTEGER
) == FAILURE
)
4676 if (type_check (result
, 1, BT_CHARACTER
) == FAILURE
)
4678 if (kind_value_check (result
, 1, gfc_default_character_kind
) == FAILURE
)
4686 gfc_check_dtime_etime (gfc_expr
*x
)
4688 if (array_check (x
, 0) == FAILURE
)
4691 if (rank_check (x
, 0, 1) == FAILURE
)
4694 if (variable_check (x
, 0, false) == FAILURE
)
4697 if (type_check (x
, 0, BT_REAL
) == FAILURE
)
4700 if (kind_value_check(x
, 0, 4) == FAILURE
)
4708 gfc_check_dtime_etime_sub (gfc_expr
*values
, gfc_expr
*time
)
4710 if (array_check (values
, 0) == FAILURE
)
4713 if (rank_check (values
, 0, 1) == FAILURE
)
4716 if (variable_check (values
, 0, false) == FAILURE
)
4719 if (type_check (values
, 0, BT_REAL
) == FAILURE
)
4722 if (kind_value_check(values
, 0, 4) == FAILURE
)
4725 if (scalar_check (time
, 1) == FAILURE
)
4728 if (type_check (time
, 1, BT_REAL
) == FAILURE
)
4731 if (kind_value_check(time
, 1, 4) == FAILURE
)
4739 gfc_check_fdate_sub (gfc_expr
*date
)
4741 if (type_check (date
, 0, BT_CHARACTER
) == FAILURE
)
4743 if (kind_value_check (date
, 0, gfc_default_character_kind
) == FAILURE
)
4751 gfc_check_gerror (gfc_expr
*msg
)
4753 if (type_check (msg
, 0, BT_CHARACTER
) == FAILURE
)
4755 if (kind_value_check (msg
, 0, gfc_default_character_kind
) == FAILURE
)
4763 gfc_check_getcwd_sub (gfc_expr
*cwd
, gfc_expr
*status
)
4765 if (type_check (cwd
, 0, BT_CHARACTER
) == FAILURE
)
4767 if (kind_value_check (cwd
, 0, gfc_default_character_kind
) == FAILURE
)
4773 if (scalar_check (status
, 1) == FAILURE
)
4776 if (type_check (status
, 1, BT_INTEGER
) == FAILURE
)
4784 gfc_check_getarg (gfc_expr
*pos
, gfc_expr
*value
)
4786 if (type_check (pos
, 0, BT_INTEGER
) == FAILURE
)
4789 if (pos
->ts
.kind
> gfc_default_integer_kind
)
4791 gfc_error ("'%s' argument of '%s' intrinsic at %L must be of a kind "
4792 "not wider than the default kind (%d)",
4793 gfc_current_intrinsic_arg
[0]->name
, gfc_current_intrinsic
,
4794 &pos
->where
, gfc_default_integer_kind
);
4798 if (type_check (value
, 1, BT_CHARACTER
) == FAILURE
)
4800 if (kind_value_check (value
, 1, gfc_default_character_kind
) == FAILURE
)
4808 gfc_check_getlog (gfc_expr
*msg
)
4810 if (type_check (msg
, 0, BT_CHARACTER
) == FAILURE
)
4812 if (kind_value_check (msg
, 0, gfc_default_character_kind
) == FAILURE
)
4820 gfc_check_exit (gfc_expr
*status
)
4825 if (type_check (status
, 0, BT_INTEGER
) == FAILURE
)
4828 if (scalar_check (status
, 0) == FAILURE
)
4836 gfc_check_flush (gfc_expr
*unit
)
4841 if (type_check (unit
, 0, BT_INTEGER
) == FAILURE
)
4844 if (scalar_check (unit
, 0) == FAILURE
)
4852 gfc_check_free (gfc_expr
*i
)
4854 if (type_check (i
, 0, BT_INTEGER
) == FAILURE
)
4857 if (scalar_check (i
, 0) == FAILURE
)
4865 gfc_check_hostnm (gfc_expr
*name
)
4867 if (type_check (name
, 0, BT_CHARACTER
) == FAILURE
)
4869 if (kind_value_check (name
, 0, gfc_default_character_kind
) == FAILURE
)
4877 gfc_check_hostnm_sub (gfc_expr
*name
, gfc_expr
*status
)
4879 if (type_check (name
, 0, BT_CHARACTER
) == FAILURE
)
4881 if (kind_value_check (name
, 0, gfc_default_character_kind
) == FAILURE
)
4887 if (scalar_check (status
, 1) == FAILURE
)
4890 if (type_check (status
, 1, BT_INTEGER
) == FAILURE
)
4898 gfc_check_itime_idate (gfc_expr
*values
)
4900 if (array_check (values
, 0) == FAILURE
)
4903 if (rank_check (values
, 0, 1) == FAILURE
)
4906 if (variable_check (values
, 0, false) == FAILURE
)
4909 if (type_check (values
, 0, BT_INTEGER
) == FAILURE
)
4912 if (kind_value_check(values
, 0, gfc_default_integer_kind
) == FAILURE
)
4920 gfc_check_ltime_gmtime (gfc_expr
*time
, gfc_expr
*values
)
4922 if (type_check (time
, 0, BT_INTEGER
) == FAILURE
)
4925 if (kind_value_check(time
, 0, gfc_default_integer_kind
) == FAILURE
)
4928 if (scalar_check (time
, 0) == FAILURE
)
4931 if (array_check (values
, 1) == FAILURE
)
4934 if (rank_check (values
, 1, 1) == FAILURE
)
4937 if (variable_check (values
, 1, false) == FAILURE
)
4940 if (type_check (values
, 1, BT_INTEGER
) == FAILURE
)
4943 if (kind_value_check(values
, 1, gfc_default_integer_kind
) == FAILURE
)
4951 gfc_check_ttynam_sub (gfc_expr
*unit
, gfc_expr
*name
)
4953 if (scalar_check (unit
, 0) == FAILURE
)
4956 if (type_check (unit
, 0, BT_INTEGER
) == FAILURE
)
4959 if (type_check (name
, 1, BT_CHARACTER
) == FAILURE
)
4961 if (kind_value_check (name
, 1, gfc_default_character_kind
) == FAILURE
)
4969 gfc_check_isatty (gfc_expr
*unit
)
4974 if (type_check (unit
, 0, BT_INTEGER
) == FAILURE
)
4977 if (scalar_check (unit
, 0) == FAILURE
)
4985 gfc_check_isnan (gfc_expr
*x
)
4987 if (type_check (x
, 0, BT_REAL
) == FAILURE
)
4995 gfc_check_perror (gfc_expr
*string
)
4997 if (type_check (string
, 0, BT_CHARACTER
) == FAILURE
)
4999 if (kind_value_check (string
, 0, gfc_default_character_kind
) == FAILURE
)
5007 gfc_check_umask (gfc_expr
*mask
)
5009 if (type_check (mask
, 0, BT_INTEGER
) == FAILURE
)
5012 if (scalar_check (mask
, 0) == FAILURE
)
5020 gfc_check_umask_sub (gfc_expr
*mask
, gfc_expr
*old
)
5022 if (type_check (mask
, 0, BT_INTEGER
) == FAILURE
)
5025 if (scalar_check (mask
, 0) == FAILURE
)
5031 if (scalar_check (old
, 1) == FAILURE
)
5034 if (type_check (old
, 1, BT_INTEGER
) == FAILURE
)
5042 gfc_check_unlink (gfc_expr
*name
)
5044 if (type_check (name
, 0, BT_CHARACTER
) == FAILURE
)
5046 if (kind_value_check (name
, 0, gfc_default_character_kind
) == FAILURE
)
5054 gfc_check_unlink_sub (gfc_expr
*name
, gfc_expr
*status
)
5056 if (type_check (name
, 0, BT_CHARACTER
) == FAILURE
)
5058 if (kind_value_check (name
, 0, gfc_default_character_kind
) == FAILURE
)
5064 if (scalar_check (status
, 1) == FAILURE
)
5067 if (type_check (status
, 1, BT_INTEGER
) == FAILURE
)
5075 gfc_check_signal (gfc_expr
*number
, gfc_expr
*handler
)
5077 if (scalar_check (number
, 0) == FAILURE
)
5079 if (type_check (number
, 0, BT_INTEGER
) == FAILURE
)
5082 if (int_or_proc_check (handler
, 1) == FAILURE
)
5084 if (handler
->ts
.type
== BT_INTEGER
&& scalar_check (handler
, 1) == FAILURE
)
5092 gfc_check_signal_sub (gfc_expr
*number
, gfc_expr
*handler
, gfc_expr
*status
)
5094 if (scalar_check (number
, 0) == FAILURE
)
5096 if (type_check (number
, 0, BT_INTEGER
) == FAILURE
)
5099 if (int_or_proc_check (handler
, 1) == FAILURE
)
5101 if (handler
->ts
.type
== BT_INTEGER
&& scalar_check (handler
, 1) == FAILURE
)
5107 if (type_check (status
, 2, BT_INTEGER
) == FAILURE
)
5109 if (scalar_check (status
, 2) == FAILURE
)
5117 gfc_check_system_sub (gfc_expr
*cmd
, gfc_expr
*status
)
5119 if (type_check (cmd
, 0, BT_CHARACTER
) == FAILURE
)
5121 if (kind_value_check (cmd
, 0, gfc_default_character_kind
) == FAILURE
)
5124 if (scalar_check (status
, 1) == FAILURE
)
5127 if (type_check (status
, 1, BT_INTEGER
) == FAILURE
)
5130 if (kind_value_check (status
, 1, gfc_default_integer_kind
) == FAILURE
)
5137 /* This is used for the GNU intrinsics AND, OR and XOR. */
5139 gfc_check_and (gfc_expr
*i
, gfc_expr
*j
)
5141 if (i
->ts
.type
!= BT_INTEGER
&& i
->ts
.type
!= BT_LOGICAL
)
5143 gfc_error ("'%s' argument of '%s' intrinsic at %L must be INTEGER "
5144 "or LOGICAL", gfc_current_intrinsic_arg
[0]->name
,
5145 gfc_current_intrinsic
, &i
->where
);
5149 if (j
->ts
.type
!= BT_INTEGER
&& j
->ts
.type
!= BT_LOGICAL
)
5151 gfc_error ("'%s' argument of '%s' intrinsic at %L must be INTEGER "
5152 "or LOGICAL", gfc_current_intrinsic_arg
[1]->name
,
5153 gfc_current_intrinsic
, &j
->where
);
5157 if (i
->ts
.type
!= j
->ts
.type
)
5159 gfc_error ("'%s' and '%s' arguments of '%s' intrinsic at %L must "
5160 "have the same type", gfc_current_intrinsic_arg
[0]->name
,
5161 gfc_current_intrinsic_arg
[1]->name
, gfc_current_intrinsic
,
5166 if (scalar_check (i
, 0) == FAILURE
)
5169 if (scalar_check (j
, 1) == FAILURE
)
5177 gfc_check_storage_size (gfc_expr
*a ATTRIBUTE_UNUSED
, gfc_expr
*kind
)
5182 if (type_check (kind
, 1, BT_INTEGER
) == FAILURE
)
5185 if (scalar_check (kind
, 1) == FAILURE
)
5188 if (kind
->expr_type
!= EXPR_CONSTANT
)
5190 gfc_error ("'%s' argument of '%s' intrinsic at %L must be a constant",
5191 gfc_current_intrinsic_arg
[1]->name
, gfc_current_intrinsic
,