2 Copyright (C) 2002-2021 Free Software Foundation, Inc.
3 Contributed by Andy Vaught & Katherine Holcomb
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 3, or (at your option) any later
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING3. If not see
19 <http://www.gnu.org/licenses/>. */
22 /* These functions check to see if an argument list is compatible with
23 a particular intrinsic function or subroutine. Presence of
24 required arguments has already been established, the argument list
25 has been sorted into the right order and has NULL arguments in the
26 correct places for missing optional arguments. */
30 #include "coretypes.h"
33 #include "intrinsic.h"
34 #include "constructor.h"
35 #include "target-memory.h"
38 /* Reset a BOZ to a zero value. This is used to prevent run-on errors
39 from resolve.c(resolve_function). */
42 reset_boz (gfc_expr
*x
)
49 x
->ts
.type
= BT_INTEGER
;
50 x
->ts
.kind
= gfc_default_integer_kind
;
51 mpz_init (x
->value
.integer
);
52 mpz_set_ui (x
->value
.integer
, 0);
55 /* A BOZ literal constant can appear in a limited number of contexts.
56 gfc_invalid_boz() is a helper function to simplify error/warning
57 generation. gfortran accepts the nonstandard 'X' for 'Z', and gfortran
58 allows the BOZ indicator to appear as a suffix. If -fallow-invalid-boz
59 is used, then issue a warning; otherwise issue an error. */
62 gfc_invalid_boz (const char *msg
, locus
*loc
)
64 if (flag_allow_invalid_boz
)
66 gfc_warning (0, msg
, loc
);
70 const char *hint
= _(" [see %<-fno-allow-invalid-boz%>]");
71 size_t len
= strlen (msg
) + strlen (hint
) + 1;
72 char *msg2
= (char *) alloca (len
);
75 gfc_error (msg2
, loc
);
80 /* Issue an error for an illegal BOZ argument. */
83 illegal_boz_arg (gfc_expr
*x
)
85 if (x
->ts
.type
== BT_BOZ
)
87 gfc_error ("BOZ literal constant at %L cannot be an actual argument "
88 "to %qs", &x
->where
, gfc_current_intrinsic
);
96 /* Some precedures take two arguments such that both cannot be BOZ. */
99 boz_args_check(gfc_expr
*i
, gfc_expr
*j
)
101 if (i
->ts
.type
== BT_BOZ
&& j
->ts
.type
== BT_BOZ
)
103 gfc_error ("Arguments of %qs at %L and %L cannot both be BOZ "
104 "literal constants", gfc_current_intrinsic
, &i
->where
,
116 /* Check that a BOZ is a constant. */
119 is_boz_constant (gfc_expr
*a
)
121 if (a
->expr_type
!= EXPR_CONSTANT
)
123 gfc_error ("Invalid use of BOZ literal constant at %L", &a
->where
);
131 /* Convert a octal string into a binary string. This is used in the
132 fallback conversion of an octal string to a REAL. */
135 oct2bin(int nbits
, char *oct
)
137 const char bits
[8][5] = {
138 "000", "001", "010", "011", "100", "101", "110", "111"};
144 if (nbits
== 64) j
++;
146 bufp
= buf
= XCNEWVEC (char, j
+ 1);
147 memset (bufp
, 0, j
+ 1);
150 for (i
= 0; i
< n
; i
++, oct
++)
153 strcpy (bufp
, &bits
[j
][0]);
157 bufp
= XCNEWVEC (char, nbits
+ 1);
159 strcpy (bufp
, buf
+ 2);
161 strcpy (bufp
, buf
+ 1);
169 /* Convert a hexidecimal string into a binary string. This is used in the
170 fallback conversion of a hexidecimal string to a REAL. */
173 hex2bin(int nbits
, char *hex
)
175 const char bits
[16][5] = {
176 "0000", "0001", "0010", "0011", "0100", "0101", "0110", "0111",
177 "1000", "1001", "1010", "1011", "1100", "1101", "1110", "1111"};
182 bufp
= buf
= XCNEWVEC (char, nbits
+ 1);
183 memset (bufp
, 0, nbits
+ 1);
186 for (i
= 0; i
< n
; i
++, hex
++)
189 if (j
> 47 && j
< 58)
191 else if (j
> 64 && j
< 71)
193 else if (j
> 96 && j
< 103)
198 strcpy (bufp
, &bits
[j
][0]);
206 /* Fallback conversion of a BOZ string to REAL. */
209 bin2real (gfc_expr
*x
, int kind
)
216 i
= gfc_validate_kind (BT_REAL
, kind
, false);
217 t
= gfc_real_kinds
[i
].digits
- 1;
219 /* Number of bits in the exponent. */
220 if (gfc_real_kinds
[i
].max_exponent
== 16384)
222 else if (gfc_real_kinds
[i
].max_exponent
== 1024)
227 if (x
->boz
.rdx
== 16)
228 sp
= hex2bin (gfc_real_kinds
[i
].mode_precision
, x
->boz
.str
);
229 else if (x
->boz
.rdx
== 8)
230 sp
= oct2bin (gfc_real_kinds
[i
].mode_precision
, x
->boz
.str
);
234 /* Extract sign bit. */
237 /* Extract biased exponent. */
238 memset (buf
, 0, 114);
239 strncpy (buf
, ++sp
, w
);
241 mpz_set_str (em
, buf
, 2);
242 ie
= mpz_get_si (em
);
244 mpfr_init2 (x
->value
.real
, t
+ 1);
245 x
->ts
.type
= BT_REAL
;
248 sp
+= w
; /* Set to first digit in significand. */
250 if ((i
== 0 && ie
== b
) || (i
== 1 && ie
== b
)
251 || ((i
== 2 || i
== 3) && ie
== b
))
265 mpfr_set_inf (x
->value
.real
, 1);
267 mpfr_set_nan (x
->value
.real
);
272 strncpy (buf
, sp
, t
+ 1);
275 /* Significand with hidden bit. */
277 strncpy (&buf
[1], sp
, t
);
280 /* Convert to significand to integer. */
281 mpz_set_str (em
, buf
, 2);
282 ie
-= ((1 << (w
- 1)) - 1); /* Unbiased exponent. */
283 mpfr_set_z_2exp (x
->value
.real
, em
, ie
- t
, GFC_RND_MODE
);
286 if (sgn
) mpfr_neg (x
->value
.real
, x
->value
.real
, GFC_RND_MODE
);
292 /* Fortran 2018 treats a BOZ as simply a string of bits. gfc_boz2real ()
293 converts the string into a REAL of the appropriate kind. The treatment
294 of the sign bit is processor dependent. */
297 gfc_boz2real (gfc_expr
*x
, int kind
)
299 extern int gfc_max_integer_kind
;
304 if (!is_boz_constant (x
))
307 /* Determine the length of the required string. */
309 if (x
->boz
.rdx
== 16) len
/= 4;
310 if (x
->boz
.rdx
== 8) len
= len
/ 3 + 1;
311 buf
= (char *) alloca (len
+ 1); /* +1 for NULL terminator. */
313 if (x
->boz
.len
>= len
) /* Truncate if necessary. */
315 str
= x
->boz
.str
+ (x
->boz
.len
- len
);
318 else /* Copy and pad. */
320 memset (buf
, 48, len
);
321 str
= buf
+ (len
- x
->boz
.len
);
322 strcpy (str
, x
->boz
.str
);
325 /* Need to adjust leading bits in an octal string. */
328 /* Clear first bit. */
329 if (kind
== 4 || kind
== 10 || kind
== 16)
333 else if (buf
[0] == '5')
335 else if (buf
[0] == '6')
337 else if (buf
[0] == '7')
340 /* Clear first two bits. */
343 if (buf
[0] == '2' || buf
[0] == '4' || buf
[0] == '6')
345 else if (buf
[0] == '3' || buf
[0] == '5' || buf
[0] == '7')
350 /* Reset BOZ string to the truncated or padded version. */
353 x
->boz
.str
= XCNEWVEC (char, len
+ 1);
354 strncpy (x
->boz
.str
, buf
, len
);
356 /* For some targets, the largest INTEGER in terms of bits is smaller than
357 the bits needed to hold the REAL. Fortunately, the kind type parameter
358 indicates the number of bytes required to an INTEGER and a REAL. */
359 if (gfc_max_integer_kind
< kind
)
365 /* Convert to widest possible integer. */
366 gfc_boz2int (x
, gfc_max_integer_kind
);
369 if (!gfc_convert_boz (x
, &ts
))
371 gfc_error ("Failure in conversion of BOZ to REAL at %L", &x
->where
);
380 /* Fortran 2018 treats a BOZ as simply a string of bits. gfc_boz2int ()
381 converts the string into an INTEGER of the appropriate kind. The
382 treatment of the sign bit is processor dependent. If the converted
383 value exceeds the range of the type, then wrap-around semantics are
387 gfc_boz2int (gfc_expr
*x
, int kind
)
393 if (!is_boz_constant (x
))
396 i
= gfc_validate_kind (BT_INTEGER
, kind
, false);
397 len
= gfc_integer_kinds
[i
].bit_size
;
398 if (x
->boz
.rdx
== 16) len
/= 4;
399 if (x
->boz
.rdx
== 8) len
= len
/ 3 + 1;
400 buf
= (char *) alloca (len
+ 1); /* +1 for NULL terminator. */
402 if (x
->boz
.len
>= len
) /* Truncate if necessary. */
404 str
= x
->boz
.str
+ (x
->boz
.len
- len
);
407 else /* Copy and pad. */
409 memset (buf
, 48, len
);
410 str
= buf
+ (len
- x
->boz
.len
);
411 strcpy (str
, x
->boz
.str
);
414 /* Need to adjust leading bits in an octal string. */
417 /* Clear first bit. */
418 if (kind
== 1 || kind
== 4 || kind
== 16)
422 else if (buf
[0] == '5')
424 else if (buf
[0] == '6')
426 else if (buf
[0] == '7')
429 /* Clear first two bits. */
432 if (buf
[0] == '2' || buf
[0] == '4' || buf
[0] == '6')
434 else if (buf
[0] == '3' || buf
[0] == '5' || buf
[0] == '7')
439 /* Convert as-if unsigned integer. */
441 mpz_set_str (tmp1
, buf
, x
->boz
.rdx
);
443 /* Check for wrap-around. */
444 if (mpz_cmp (tmp1
, gfc_integer_kinds
[i
].huge
) > 0)
448 mpz_add_ui (tmp2
, gfc_integer_kinds
[i
].huge
, 1);
449 mpz_mod (tmp1
, tmp1
, tmp2
);
450 mpz_sub (tmp1
, tmp1
, tmp2
);
454 /* Clear boz info. */
459 mpz_init (x
->value
.integer
);
460 mpz_set (x
->value
.integer
, tmp1
);
461 x
->ts
.type
= BT_INTEGER
;
469 /* Make sure an expression is a scalar. */
472 scalar_check (gfc_expr
*e
, int n
)
477 gfc_error ("%qs argument of %qs intrinsic at %L must be a scalar",
478 gfc_current_intrinsic_arg
[n
]->name
, gfc_current_intrinsic
,
485 /* Check the type of an expression. */
488 type_check (gfc_expr
*e
, int n
, bt type
)
490 if (e
->ts
.type
== type
)
493 gfc_error ("%qs argument of %qs intrinsic at %L must be %s",
494 gfc_current_intrinsic_arg
[n
]->name
, gfc_current_intrinsic
,
495 &e
->where
, gfc_basic_typename (type
));
501 /* Check that the expression is a numeric type. */
504 numeric_check (gfc_expr
*e
, int n
)
506 /* Users sometime use a subroutine designator as an actual argument to
507 an intrinsic subprogram that expects an argument with a numeric type. */
508 if (e
->symtree
&& e
->symtree
->n
.sym
->attr
.subroutine
)
511 if (gfc_numeric_ts (&e
->ts
))
514 /* If the expression has not got a type, check if its namespace can
515 offer a default type. */
516 if ((e
->expr_type
== EXPR_VARIABLE
|| e
->expr_type
== EXPR_FUNCTION
)
517 && e
->symtree
->n
.sym
->ts
.type
== BT_UNKNOWN
518 && gfc_set_default_type (e
->symtree
->n
.sym
, 0, e
->symtree
->n
.sym
->ns
)
519 && gfc_numeric_ts (&e
->symtree
->n
.sym
->ts
))
521 e
->ts
= e
->symtree
->n
.sym
->ts
;
527 gfc_error ("%qs argument of %qs intrinsic at %L must have a numeric type",
528 gfc_current_intrinsic_arg
[n
]->name
, gfc_current_intrinsic
,
535 /* Check that an expression is integer or real. */
538 int_or_real_check (gfc_expr
*e
, int n
)
540 if (e
->ts
.type
!= BT_INTEGER
&& e
->ts
.type
!= BT_REAL
)
542 gfc_error ("%qs argument of %qs intrinsic at %L must be INTEGER "
543 "or REAL", gfc_current_intrinsic_arg
[n
]->name
,
544 gfc_current_intrinsic
, &e
->where
);
551 /* Check that an expression is integer or real; allow character for
555 int_or_real_or_char_check_f2003 (gfc_expr
*e
, int n
)
557 if (e
->ts
.type
!= BT_INTEGER
&& e
->ts
.type
!= BT_REAL
)
559 if (e
->ts
.type
== BT_CHARACTER
)
560 return gfc_notify_std (GFC_STD_F2003
, "Fortran 2003: Character for "
561 "%qs argument of %qs intrinsic at %L",
562 gfc_current_intrinsic_arg
[n
]->name
,
563 gfc_current_intrinsic
, &e
->where
);
566 if (gfc_option
.allow_std
& GFC_STD_F2003
)
567 gfc_error ("%qs argument of %qs intrinsic at %L must be INTEGER "
568 "or REAL or CHARACTER",
569 gfc_current_intrinsic_arg
[n
]->name
,
570 gfc_current_intrinsic
, &e
->where
);
572 gfc_error ("%qs argument of %qs intrinsic at %L must be INTEGER "
573 "or REAL", gfc_current_intrinsic_arg
[n
]->name
,
574 gfc_current_intrinsic
, &e
->where
);
582 /* Check that an expression is an intrinsic type. */
584 intrinsic_type_check (gfc_expr
*e
, int n
)
586 if (e
->ts
.type
!= BT_INTEGER
&& e
->ts
.type
!= BT_REAL
587 && e
->ts
.type
!= BT_COMPLEX
&& e
->ts
.type
!= BT_CHARACTER
588 && e
->ts
.type
!= BT_LOGICAL
)
590 gfc_error ("%qs argument of %qs intrinsic at %L must be of intrinsic type",
591 gfc_current_intrinsic_arg
[n
]->name
,
592 gfc_current_intrinsic
, &e
->where
);
598 /* Check that an expression is real or complex. */
601 real_or_complex_check (gfc_expr
*e
, int n
)
603 if (e
->ts
.type
!= BT_REAL
&& e
->ts
.type
!= BT_COMPLEX
)
605 gfc_error ("%qs argument of %qs intrinsic at %L must be REAL "
606 "or COMPLEX", gfc_current_intrinsic_arg
[n
]->name
,
607 gfc_current_intrinsic
, &e
->where
);
615 /* Check that an expression is INTEGER or PROCEDURE. */
618 int_or_proc_check (gfc_expr
*e
, int n
)
620 if (e
->ts
.type
!= BT_INTEGER
&& e
->ts
.type
!= BT_PROCEDURE
)
622 gfc_error ("%qs argument of %qs intrinsic at %L must be INTEGER "
623 "or PROCEDURE", gfc_current_intrinsic_arg
[n
]->name
,
624 gfc_current_intrinsic
, &e
->where
);
632 /* Check that the expression is an optional constant integer
633 and that it specifies a valid kind for that type. */
636 kind_check (gfc_expr
*k
, int n
, bt type
)
643 if (!type_check (k
, n
, BT_INTEGER
))
646 if (!scalar_check (k
, n
))
649 if (!gfc_check_init_expr (k
))
651 gfc_error ("%qs argument of %qs intrinsic at %L must be a constant",
652 gfc_current_intrinsic_arg
[n
]->name
, gfc_current_intrinsic
,
657 if (gfc_extract_int (k
, &kind
)
658 || gfc_validate_kind (type
, kind
, true) < 0)
660 gfc_error ("Invalid kind for %s at %L", gfc_basic_typename (type
),
669 /* Make sure the expression is a double precision real. */
672 double_check (gfc_expr
*d
, int n
)
674 if (!type_check (d
, n
, BT_REAL
))
677 if (d
->ts
.kind
!= gfc_default_double_kind
)
679 gfc_error ("%qs argument of %qs intrinsic at %L must be double "
680 "precision", gfc_current_intrinsic_arg
[n
]->name
,
681 gfc_current_intrinsic
, &d
->where
);
690 coarray_check (gfc_expr
*e
, int n
)
692 if (e
->ts
.type
== BT_CLASS
&& gfc_expr_attr (e
).class_ok
693 && CLASS_DATA (e
)->attr
.codimension
694 && CLASS_DATA (e
)->as
->corank
)
696 gfc_add_class_array_ref (e
);
700 if (!gfc_is_coarray (e
))
702 gfc_error ("Expected coarray variable as %qs argument to the %s "
703 "intrinsic at %L", gfc_current_intrinsic_arg
[n
]->name
,
704 gfc_current_intrinsic
, &e
->where
);
712 /* Make sure the expression is a logical array. */
715 logical_array_check (gfc_expr
*array
, int n
)
717 if (array
->ts
.type
!= BT_LOGICAL
|| array
->rank
== 0)
719 gfc_error ("%qs argument of %qs intrinsic at %L must be a logical "
720 "array", gfc_current_intrinsic_arg
[n
]->name
,
721 gfc_current_intrinsic
, &array
->where
);
729 /* Make sure an expression is an array. */
732 array_check (gfc_expr
*e
, int n
)
734 if (e
->rank
!= 0 && e
->ts
.type
== BT_CLASS
&& gfc_expr_attr (e
).class_ok
735 && CLASS_DATA (e
)->attr
.dimension
736 && CLASS_DATA (e
)->as
->rank
)
738 gfc_add_class_array_ref (e
);
741 if (e
->rank
!= 0 && e
->ts
.type
!= BT_PROCEDURE
)
744 gfc_error ("%qs argument of %qs intrinsic at %L must be an array",
745 gfc_current_intrinsic_arg
[n
]->name
, gfc_current_intrinsic
,
752 /* If expr is a constant, then check to ensure that it is greater than
756 nonnegative_check (const char *arg
, gfc_expr
*expr
)
760 if (expr
->expr_type
== EXPR_CONSTANT
)
762 gfc_extract_int (expr
, &i
);
765 gfc_error ("%qs at %L must be nonnegative", arg
, &expr
->where
);
774 /* If expr is a constant, then check to ensure that it is greater than zero. */
777 positive_check (int n
, gfc_expr
*expr
)
781 if (expr
->expr_type
== EXPR_CONSTANT
)
783 gfc_extract_int (expr
, &i
);
786 gfc_error ("%qs argument of %qs intrinsic at %L must be positive",
787 gfc_current_intrinsic_arg
[n
]->name
, gfc_current_intrinsic
,
797 /* If expr2 is constant, then check that the value is less than
798 (less than or equal to, if 'or_equal' is true) bit_size(expr1). */
801 less_than_bitsize1 (const char *arg1
, gfc_expr
*expr1
, const char *arg2
,
802 gfc_expr
*expr2
, bool or_equal
)
806 if (expr2
->expr_type
== EXPR_CONSTANT
)
808 gfc_extract_int (expr2
, &i2
);
809 i3
= gfc_validate_kind (BT_INTEGER
, expr1
->ts
.kind
, false);
811 /* For ISHFT[C], check that |shift| <= bit_size(i). */
817 if (i2
> gfc_integer_kinds
[i3
].bit_size
)
819 gfc_error ("The absolute value of SHIFT at %L must be less "
820 "than or equal to BIT_SIZE(%qs)",
821 &expr2
->where
, arg1
);
828 if (i2
> gfc_integer_kinds
[i3
].bit_size
)
830 gfc_error ("%qs at %L must be less than "
831 "or equal to BIT_SIZE(%qs)",
832 arg2
, &expr2
->where
, arg1
);
838 if (i2
>= gfc_integer_kinds
[i3
].bit_size
)
840 gfc_error ("%qs at %L must be less than BIT_SIZE(%qs)",
841 arg2
, &expr2
->where
, arg1
);
851 /* If expr is constant, then check that the value is less than or equal
852 to the bit_size of the kind k. */
855 less_than_bitsizekind (const char *arg
, gfc_expr
*expr
, int k
)
859 if (expr
->expr_type
!= EXPR_CONSTANT
)
862 i
= gfc_validate_kind (BT_INTEGER
, k
, false);
863 gfc_extract_int (expr
, &val
);
865 if (val
> gfc_integer_kinds
[i
].bit_size
)
867 gfc_error ("%qs at %L must be less than or equal to the BIT_SIZE of "
868 "INTEGER(KIND=%d)", arg
, &expr
->where
, k
);
876 /* If expr2 and expr3 are constants, then check that the value is less than
877 or equal to bit_size(expr1). */
880 less_than_bitsize2 (const char *arg1
, gfc_expr
*expr1
, const char *arg2
,
881 gfc_expr
*expr2
, const char *arg3
, gfc_expr
*expr3
)
885 if (expr2
->expr_type
== EXPR_CONSTANT
&& expr3
->expr_type
== EXPR_CONSTANT
)
887 gfc_extract_int (expr2
, &i2
);
888 gfc_extract_int (expr3
, &i3
);
890 i3
= gfc_validate_kind (BT_INTEGER
, expr1
->ts
.kind
, false);
891 if (i2
> gfc_integer_kinds
[i3
].bit_size
)
893 gfc_error ("%<%s + %s%> at %L must be less than or equal "
895 arg2
, arg3
, &expr2
->where
, arg1
);
903 /* Make sure two expressions have the same type. */
906 same_type_check (gfc_expr
*e
, int n
, gfc_expr
*f
, int m
, bool assoc
= false)
908 gfc_typespec
*ets
= &e
->ts
;
909 gfc_typespec
*fts
= &f
->ts
;
913 /* Procedure pointer component expressions have the type of the interface
914 procedure. If they are being tested for association with a procedure
915 pointer (ie. not a component), the type of the procedure must be
917 if (e
->ts
.type
== BT_PROCEDURE
&& e
->symtree
->n
.sym
)
918 ets
= &e
->symtree
->n
.sym
->ts
;
919 if (f
->ts
.type
== BT_PROCEDURE
&& f
->symtree
->n
.sym
)
920 fts
= &f
->symtree
->n
.sym
->ts
;
923 if (gfc_compare_types (ets
, fts
))
926 gfc_error ("%qs argument of %qs intrinsic at %L must be the same type "
927 "and kind as %qs", gfc_current_intrinsic_arg
[m
]->name
,
928 gfc_current_intrinsic
, &f
->where
,
929 gfc_current_intrinsic_arg
[n
]->name
);
935 /* Make sure that an expression has a certain (nonzero) rank. */
938 rank_check (gfc_expr
*e
, int n
, int rank
)
943 gfc_error ("%qs argument of %qs intrinsic at %L must be of rank %d",
944 gfc_current_intrinsic_arg
[n
]->name
, gfc_current_intrinsic
,
951 /* Make sure a variable expression is not an optional dummy argument. */
954 nonoptional_check (gfc_expr
*e
, int n
)
956 if (e
->expr_type
== EXPR_VARIABLE
&& e
->symtree
->n
.sym
->attr
.optional
)
958 gfc_error ("%qs argument of %qs intrinsic at %L must not be OPTIONAL",
959 gfc_current_intrinsic_arg
[n
]->name
, gfc_current_intrinsic
,
963 /* TODO: Recursive check on nonoptional variables? */
969 /* Check for ALLOCATABLE attribute. */
972 allocatable_check (gfc_expr
*e
, int n
)
974 symbol_attribute attr
;
976 attr
= gfc_variable_attr (e
, NULL
);
977 if (!attr
.allocatable
978 || (attr
.associate_var
&& !attr
.select_rank_temporary
))
980 gfc_error ("%qs argument of %qs intrinsic at %L must be ALLOCATABLE",
981 gfc_current_intrinsic_arg
[n
]->name
, gfc_current_intrinsic
,
990 /* Check that an expression has a particular kind. */
993 kind_value_check (gfc_expr
*e
, int n
, int k
)
998 gfc_error ("%qs argument of %qs intrinsic at %L must be of kind %d",
999 gfc_current_intrinsic_arg
[n
]->name
, gfc_current_intrinsic
,
1006 /* Make sure an expression is a variable. */
1009 variable_check (gfc_expr
*e
, int n
, bool allow_proc
)
1011 if (e
->expr_type
== EXPR_VARIABLE
1012 && e
->symtree
->n
.sym
->attr
.intent
== INTENT_IN
1013 && (gfc_current_intrinsic_arg
[n
]->intent
== INTENT_OUT
1014 || gfc_current_intrinsic_arg
[n
]->intent
== INTENT_INOUT
))
1017 bool pointer
= e
->symtree
->n
.sym
->ts
.type
== BT_CLASS
1018 && CLASS_DATA (e
->symtree
->n
.sym
)
1019 ? CLASS_DATA (e
->symtree
->n
.sym
)->attr
.class_pointer
1020 : e
->symtree
->n
.sym
->attr
.pointer
;
1022 for (ref
= e
->ref
; ref
; ref
= ref
->next
)
1024 if (pointer
&& ref
->type
== REF_COMPONENT
)
1026 if (ref
->type
== REF_COMPONENT
1027 && ((ref
->u
.c
.component
->ts
.type
== BT_CLASS
1028 && CLASS_DATA (ref
->u
.c
.component
)->attr
.class_pointer
)
1029 || (ref
->u
.c
.component
->ts
.type
!= BT_CLASS
1030 && ref
->u
.c
.component
->attr
.pointer
)))
1036 gfc_error ("%qs argument of %qs intrinsic at %L cannot be "
1037 "INTENT(IN)", gfc_current_intrinsic_arg
[n
]->name
,
1038 gfc_current_intrinsic
, &e
->where
);
1043 if (e
->expr_type
== EXPR_VARIABLE
1044 && e
->symtree
->n
.sym
->attr
.flavor
!= FL_PARAMETER
1045 && (allow_proc
|| !e
->symtree
->n
.sym
->attr
.function
))
1048 if (e
->expr_type
== EXPR_VARIABLE
&& e
->symtree
->n
.sym
->attr
.function
1049 && e
->symtree
->n
.sym
== e
->symtree
->n
.sym
->result
)
1052 for (ns
= gfc_current_ns
; ns
; ns
= ns
->parent
)
1053 if (ns
->proc_name
== e
->symtree
->n
.sym
)
1057 /* F2018:R902: function reference having a data pointer result. */
1058 if (e
->expr_type
== EXPR_FUNCTION
1059 && e
->symtree
->n
.sym
->attr
.flavor
== FL_PROCEDURE
1060 && e
->symtree
->n
.sym
->attr
.function
1061 && e
->symtree
->n
.sym
->attr
.pointer
)
1064 gfc_error ("%qs argument of %qs intrinsic at %L must be a variable",
1065 gfc_current_intrinsic_arg
[n
]->name
, gfc_current_intrinsic
, &e
->where
);
1071 /* Check the common DIM parameter for correctness. */
1074 dim_check (gfc_expr
*dim
, int n
, bool optional
)
1079 if (!type_check (dim
, n
, BT_INTEGER
))
1082 if (!scalar_check (dim
, n
))
1085 if (!optional
&& !nonoptional_check (dim
, n
))
1092 /* If a coarray DIM parameter is a constant, make sure that it is greater than
1093 zero and less than or equal to the corank of the given array. */
1096 dim_corank_check (gfc_expr
*dim
, gfc_expr
*array
)
1100 gcc_assert (array
->expr_type
== EXPR_VARIABLE
);
1102 if (dim
->expr_type
!= EXPR_CONSTANT
)
1105 if (array
->ts
.type
== BT_CLASS
)
1108 corank
= gfc_get_corank (array
);
1110 if (mpz_cmp_ui (dim
->value
.integer
, 1) < 0
1111 || mpz_cmp_ui (dim
->value
.integer
, corank
) > 0)
1113 gfc_error ("%<dim%> argument of %qs intrinsic at %L is not a valid "
1114 "codimension index", gfc_current_intrinsic
, &dim
->where
);
1123 /* If a DIM parameter is a constant, make sure that it is greater than
1124 zero and less than or equal to the rank of the given array. If
1125 allow_assumed is zero then dim must be less than the rank of the array
1126 for assumed size arrays. */
1129 dim_rank_check (gfc_expr
*dim
, gfc_expr
*array
, int allow_assumed
)
1137 if (dim
->expr_type
!= EXPR_CONSTANT
)
1140 if (array
->expr_type
== EXPR_FUNCTION
&& array
->value
.function
.isym
1141 && array
->value
.function
.isym
->id
== GFC_ISYM_SPREAD
)
1142 rank
= array
->rank
+ 1;
1146 /* Assumed-rank array. */
1148 rank
= GFC_MAX_DIMENSIONS
;
1150 if (array
->expr_type
== EXPR_VARIABLE
)
1152 ar
= gfc_find_array_ref (array
, true);
1155 if (ar
->as
->type
== AS_ASSUMED_SIZE
1157 && ar
->type
!= AR_ELEMENT
1158 && ar
->type
!= AR_SECTION
)
1162 if (mpz_cmp_ui (dim
->value
.integer
, 1) < 0
1163 || mpz_cmp_ui (dim
->value
.integer
, rank
) > 0)
1165 gfc_error ("%<dim%> argument of %qs intrinsic at %L is not a valid "
1166 "dimension index", gfc_current_intrinsic
, &dim
->where
);
1175 /* Compare the size of a along dimension ai with the size of b along
1176 dimension bi, returning 0 if they are known not to be identical,
1177 and 1 if they are identical, or if this cannot be determined. */
1180 identical_dimen_shape (gfc_expr
*a
, int ai
, gfc_expr
*b
, int bi
)
1182 mpz_t a_size
, b_size
;
1185 gcc_assert (a
->rank
> ai
);
1186 gcc_assert (b
->rank
> bi
);
1190 if (gfc_array_dimen_size (a
, ai
, &a_size
))
1192 if (gfc_array_dimen_size (b
, bi
, &b_size
))
1194 if (mpz_cmp (a_size
, b_size
) != 0)
1204 /* Calculate the length of a character variable, including substrings.
1205 Strip away parentheses if necessary. Return -1 if no length could
1209 gfc_var_strlen (const gfc_expr
*a
)
1213 while (a
->expr_type
== EXPR_OP
&& a
->value
.op
.op
== INTRINSIC_PARENTHESES
)
1214 a
= a
->value
.op
.op1
;
1216 for (ra
= a
->ref
; ra
!= NULL
&& ra
->type
!= REF_SUBSTRING
; ra
= ra
->next
)
1221 long start_a
, end_a
;
1226 if ((!ra
->u
.ss
.start
|| ra
->u
.ss
.start
->expr_type
== EXPR_CONSTANT
)
1227 && ra
->u
.ss
.end
->expr_type
== EXPR_CONSTANT
)
1229 start_a
= ra
->u
.ss
.start
? mpz_get_si (ra
->u
.ss
.start
->value
.integer
)
1231 end_a
= mpz_get_si (ra
->u
.ss
.end
->value
.integer
);
1232 return (end_a
< start_a
) ? 0 : end_a
- start_a
+ 1;
1234 else if (ra
->u
.ss
.start
1235 && gfc_dep_compare_expr (ra
->u
.ss
.start
, ra
->u
.ss
.end
) == 0)
1241 if (a
->ts
.u
.cl
&& a
->ts
.u
.cl
->length
1242 && a
->ts
.u
.cl
->length
->expr_type
== EXPR_CONSTANT
)
1243 return mpz_get_si (a
->ts
.u
.cl
->length
->value
.integer
);
1244 else if (a
->expr_type
== EXPR_CONSTANT
1245 && (a
->ts
.u
.cl
== NULL
|| a
->ts
.u
.cl
->length
== NULL
))
1246 return a
->value
.character
.length
;
1252 /* Check whether two character expressions have the same length;
1253 returns true if they have or if the length cannot be determined,
1254 otherwise return false and raise a gfc_error. */
1257 gfc_check_same_strlen (const gfc_expr
*a
, const gfc_expr
*b
, const char *name
)
1261 len_a
= gfc_var_strlen(a
);
1262 len_b
= gfc_var_strlen(b
);
1264 if (len_a
== -1 || len_b
== -1 || len_a
== len_b
)
1268 gfc_error ("Unequal character lengths (%ld/%ld) in %s at %L",
1269 len_a
, len_b
, name
, &a
->where
);
1275 /***** Check functions *****/
1277 /* Check subroutine suitable for intrinsics taking a real argument and
1278 a kind argument for the result. */
1281 check_a_kind (gfc_expr
*a
, gfc_expr
*kind
, bt type
)
1283 if (!type_check (a
, 0, BT_REAL
))
1285 if (!kind_check (kind
, 1, type
))
1292 /* Check subroutine suitable for ceiling, floor and nint. */
1295 gfc_check_a_ikind (gfc_expr
*a
, gfc_expr
*kind
)
1297 return check_a_kind (a
, kind
, BT_INTEGER
);
1301 /* Check subroutine suitable for aint, anint. */
1304 gfc_check_a_xkind (gfc_expr
*a
, gfc_expr
*kind
)
1306 return check_a_kind (a
, kind
, BT_REAL
);
1311 gfc_check_abs (gfc_expr
*a
)
1313 if (!numeric_check (a
, 0))
1321 gfc_check_achar (gfc_expr
*a
, gfc_expr
*kind
)
1323 if (a
->ts
.type
== BT_BOZ
)
1325 if (gfc_invalid_boz (G_("BOZ literal constant at %L cannot appear in "
1326 "ACHAR intrinsic subprogram"), &a
->where
))
1329 if (!gfc_boz2int (a
, gfc_default_integer_kind
))
1333 if (!type_check (a
, 0, BT_INTEGER
))
1336 if (!kind_check (kind
, 1, BT_CHARACTER
))
1344 gfc_check_access_func (gfc_expr
*name
, gfc_expr
*mode
)
1346 if (!type_check (name
, 0, BT_CHARACTER
)
1347 || !scalar_check (name
, 0))
1349 if (!kind_value_check (name
, 0, gfc_default_character_kind
))
1352 if (!type_check (mode
, 1, BT_CHARACTER
)
1353 || !scalar_check (mode
, 1))
1355 if (!kind_value_check (mode
, 1, gfc_default_character_kind
))
1363 gfc_check_all_any (gfc_expr
*mask
, gfc_expr
*dim
)
1365 if (!logical_array_check (mask
, 0))
1368 if (!dim_check (dim
, 1, false))
1371 if (!dim_rank_check (dim
, mask
, 0))
1378 /* Limited checking for ALLOCATED intrinsic. Additional checking
1379 is performed in intrinsic.c(sort_actual), because ALLOCATED
1380 has two mutually exclusive non-optional arguments. */
1383 gfc_check_allocated (gfc_expr
*array
)
1385 /* Tests on allocated components of coarrays need to detour the check to
1386 argument of the _caf_get. */
1387 if (flag_coarray
== GFC_FCOARRAY_LIB
&& array
->expr_type
== EXPR_FUNCTION
1388 && array
->value
.function
.isym
1389 && array
->value
.function
.isym
->id
== GFC_ISYM_CAF_GET
)
1391 array
= array
->value
.function
.actual
->expr
;
1396 if (!variable_check (array
, 0, false))
1398 if (!allocatable_check (array
, 0))
1405 /* Common check function where the first argument must be real or
1406 integer and the second argument must be the same as the first. */
1409 gfc_check_a_p (gfc_expr
*a
, gfc_expr
*p
)
1411 if (!int_or_real_check (a
, 0))
1414 if (a
->ts
.type
!= p
->ts
.type
)
1416 gfc_error ("%qs and %qs arguments of %qs intrinsic at %L must "
1417 "have the same type", gfc_current_intrinsic_arg
[0]->name
,
1418 gfc_current_intrinsic_arg
[1]->name
, gfc_current_intrinsic
,
1423 if (a
->ts
.kind
!= p
->ts
.kind
)
1425 if (!gfc_notify_std (GFC_STD_GNU
, "Different type kinds at %L",
1435 gfc_check_x_yd (gfc_expr
*x
, gfc_expr
*y
)
1437 if (!double_check (x
, 0) || !double_check (y
, 1))
1444 gfc_invalid_null_arg (gfc_expr
*x
)
1446 if (x
->expr_type
== EXPR_NULL
)
1448 gfc_error ("NULL at %L is not permitted as actual argument "
1449 "to %qs intrinsic function", &x
->where
,
1450 gfc_current_intrinsic
);
1457 gfc_check_associated (gfc_expr
*pointer
, gfc_expr
*target
)
1459 symbol_attribute attr1
, attr2
;
1463 if (gfc_invalid_null_arg (pointer
))
1466 attr1
= gfc_expr_attr (pointer
);
1468 if (!attr1
.pointer
&& !attr1
.proc_pointer
)
1470 gfc_error ("%qs argument of %qs intrinsic at %L must be a POINTER",
1471 gfc_current_intrinsic_arg
[0]->name
, gfc_current_intrinsic
,
1477 if (attr1
.pointer
&& gfc_is_coindexed (pointer
))
1479 gfc_error ("%qs argument of %qs intrinsic at %L shall not be "
1480 "coindexed", gfc_current_intrinsic_arg
[0]->name
,
1481 gfc_current_intrinsic
, &pointer
->where
);
1485 /* Target argument is optional. */
1489 if (gfc_invalid_null_arg (target
))
1492 if (target
->expr_type
== EXPR_VARIABLE
|| target
->expr_type
== EXPR_FUNCTION
)
1493 attr2
= gfc_expr_attr (target
);
1496 gfc_error ("%qs argument of %qs intrinsic at %L must be a pointer "
1497 "or target VARIABLE or FUNCTION",
1498 gfc_current_intrinsic_arg
[1]->name
, gfc_current_intrinsic
,
1503 if (attr1
.pointer
&& !attr2
.pointer
&& !attr2
.target
)
1505 gfc_error ("%qs argument of %qs intrinsic at %L must be a POINTER "
1506 "or a TARGET", gfc_current_intrinsic_arg
[1]->name
,
1507 gfc_current_intrinsic
, &target
->where
);
1512 if (attr1
.pointer
&& gfc_is_coindexed (target
))
1514 gfc_error ("%qs argument of %qs intrinsic at %L shall not be "
1515 "coindexed", gfc_current_intrinsic_arg
[1]->name
,
1516 gfc_current_intrinsic
, &target
->where
);
1521 if (!same_type_check (pointer
, 0, target
, 1, true))
1523 /* F2018 C838 explicitly allows an assumed-rank variable as the first
1524 argument of intrinsic inquiry functions. */
1525 if (pointer
->rank
!= -1 && !rank_check (target
, 0, pointer
->rank
))
1527 if (target
->rank
> 0)
1529 for (i
= 0; i
< target
->rank
; i
++)
1530 if (target
->ref
->u
.ar
.dimen_type
[i
] == DIMEN_VECTOR
)
1532 gfc_error ("Array section with a vector subscript at %L shall not "
1533 "be the target of a pointer",
1544 gfc_check_atan_2 (gfc_expr
*y
, gfc_expr
*x
)
1546 /* gfc_notify_std would be a waste of time as the return value
1547 is seemingly used only for the generic resolution. The error
1548 will be: Too many arguments. */
1549 if ((gfc_option
.allow_std
& GFC_STD_F2008
) == 0)
1552 return gfc_check_atan2 (y
, x
);
1557 gfc_check_atan2 (gfc_expr
*y
, gfc_expr
*x
)
1559 if (!type_check (y
, 0, BT_REAL
))
1561 if (!same_type_check (y
, 0, x
, 1))
1569 gfc_check_atomic (gfc_expr
*atom
, int atom_no
, gfc_expr
*value
, int val_no
,
1570 gfc_expr
*stat
, int stat_no
)
1572 if (!scalar_check (atom
, atom_no
) || !scalar_check (value
, val_no
))
1575 if (!(atom
->ts
.type
== BT_INTEGER
&& atom
->ts
.kind
== gfc_atomic_int_kind
)
1576 && !(atom
->ts
.type
== BT_LOGICAL
1577 && atom
->ts
.kind
== gfc_atomic_logical_kind
))
1579 gfc_error ("ATOM argument at %L to intrinsic function %s shall be an "
1580 "integer of ATOMIC_INT_KIND or a logical of "
1581 "ATOMIC_LOGICAL_KIND", &atom
->where
, gfc_current_intrinsic
);
1585 if (!gfc_is_coarray (atom
) && !gfc_is_coindexed (atom
))
1587 gfc_error ("ATOM argument at %L of the %s intrinsic function shall be a "
1588 "coarray or coindexed", &atom
->where
, gfc_current_intrinsic
);
1592 if (atom
->ts
.type
!= value
->ts
.type
)
1594 gfc_error ("%qs argument of %qs intrinsic at %L shall have the same "
1595 "type as %qs at %L", gfc_current_intrinsic_arg
[val_no
]->name
,
1596 gfc_current_intrinsic
, &value
->where
,
1597 gfc_current_intrinsic_arg
[atom_no
]->name
, &atom
->where
);
1603 if (!type_check (stat
, stat_no
, BT_INTEGER
))
1605 if (!scalar_check (stat
, stat_no
))
1607 if (!variable_check (stat
, stat_no
, false))
1609 if (!kind_value_check (stat
, stat_no
, gfc_default_integer_kind
))
1612 if (!gfc_notify_std (GFC_STD_F2018
, "STAT= argument to %s at %L",
1613 gfc_current_intrinsic
, &stat
->where
))
1622 gfc_check_atomic_def (gfc_expr
*atom
, gfc_expr
*value
, gfc_expr
*stat
)
1624 if (atom
->expr_type
== EXPR_FUNCTION
1625 && atom
->value
.function
.isym
1626 && atom
->value
.function
.isym
->id
== GFC_ISYM_CAF_GET
)
1627 atom
= atom
->value
.function
.actual
->expr
;
1629 if (!gfc_check_vardef_context (atom
, false, false, false, NULL
))
1631 gfc_error ("ATOM argument of the %s intrinsic function at %L shall be "
1632 "definable", gfc_current_intrinsic
, &atom
->where
);
1636 return gfc_check_atomic (atom
, 0, value
, 1, stat
, 2);
1641 gfc_check_atomic_op (gfc_expr
*atom
, gfc_expr
*value
, gfc_expr
*stat
)
1643 if (atom
->ts
.type
!= BT_INTEGER
|| atom
->ts
.kind
!= gfc_atomic_int_kind
)
1645 gfc_error ("ATOM argument at %L to intrinsic function %s shall be an "
1646 "integer of ATOMIC_INT_KIND", &atom
->where
,
1647 gfc_current_intrinsic
);
1651 return gfc_check_atomic_def (atom
, value
, stat
);
1656 gfc_check_atomic_ref (gfc_expr
*value
, gfc_expr
*atom
, gfc_expr
*stat
)
1658 if (atom
->expr_type
== EXPR_FUNCTION
1659 && atom
->value
.function
.isym
1660 && atom
->value
.function
.isym
->id
== GFC_ISYM_CAF_GET
)
1661 atom
= atom
->value
.function
.actual
->expr
;
1663 if (!gfc_check_vardef_context (value
, false, false, false, NULL
))
1665 gfc_error ("VALUE argument of the %s intrinsic function at %L shall be "
1666 "definable", gfc_current_intrinsic
, &value
->where
);
1670 return gfc_check_atomic (atom
, 1, value
, 0, stat
, 2);
1675 gfc_check_image_status (gfc_expr
*image
, gfc_expr
*team
)
1677 /* IMAGE has to be a positive, scalar integer. */
1678 if (!type_check (image
, 0, BT_INTEGER
) || !scalar_check (image
, 0)
1679 || !positive_check (0, image
))
1684 gfc_error ("%qs argument of %qs intrinsic at %L not yet supported",
1685 gfc_current_intrinsic_arg
[1]->name
, gfc_current_intrinsic
,
1694 gfc_check_failed_or_stopped_images (gfc_expr
*team
, gfc_expr
*kind
)
1698 gfc_error ("%qs argument of %qs intrinsic at %L not yet supported",
1699 gfc_current_intrinsic_arg
[0]->name
, gfc_current_intrinsic
,
1708 if (!type_check (kind
, 1, BT_INTEGER
) || !scalar_check (kind
, 1)
1709 || !positive_check (1, kind
))
1712 /* Get the kind, reporting error on non-constant or overflow. */
1713 gfc_current_locus
= kind
->where
;
1714 if (gfc_extract_int (kind
, &k
, 1))
1716 if (gfc_validate_kind (BT_INTEGER
, k
, true) == -1)
1718 gfc_error ("%qs argument of %qs intrinsic at %L shall specify a "
1719 "valid integer kind", gfc_current_intrinsic_arg
[1]->name
,
1720 gfc_current_intrinsic
, &kind
->where
);
1729 gfc_check_get_team (gfc_expr
*level
)
1733 gfc_error ("%qs argument of %qs intrinsic at %L not yet supported",
1734 gfc_current_intrinsic_arg
[0]->name
, gfc_current_intrinsic
,
1743 gfc_check_atomic_cas (gfc_expr
*atom
, gfc_expr
*old
, gfc_expr
*compare
,
1744 gfc_expr
*new_val
, gfc_expr
*stat
)
1746 if (atom
->expr_type
== EXPR_FUNCTION
1747 && atom
->value
.function
.isym
1748 && atom
->value
.function
.isym
->id
== GFC_ISYM_CAF_GET
)
1749 atom
= atom
->value
.function
.actual
->expr
;
1751 if (!gfc_check_atomic (atom
, 0, new_val
, 3, stat
, 4))
1754 if (!scalar_check (old
, 1) || !scalar_check (compare
, 2))
1757 if (!same_type_check (atom
, 0, old
, 1))
1760 if (!same_type_check (atom
, 0, compare
, 2))
1763 if (!gfc_check_vardef_context (atom
, false, false, false, NULL
))
1765 gfc_error ("ATOM argument of the %s intrinsic function at %L shall be "
1766 "definable", gfc_current_intrinsic
, &atom
->where
);
1770 if (!gfc_check_vardef_context (old
, false, false, false, NULL
))
1772 gfc_error ("OLD argument of the %s intrinsic function at %L shall be "
1773 "definable", gfc_current_intrinsic
, &old
->where
);
1781 gfc_check_event_query (gfc_expr
*event
, gfc_expr
*count
, gfc_expr
*stat
)
1783 if (event
->ts
.type
!= BT_DERIVED
1784 || event
->ts
.u
.derived
->from_intmod
!= INTMOD_ISO_FORTRAN_ENV
1785 || event
->ts
.u
.derived
->intmod_sym_id
!= ISOFORTRAN_EVENT_TYPE
)
1787 gfc_error ("EVENT argument at %L to the intrinsic EVENT_QUERY "
1788 "shall be of type EVENT_TYPE", &event
->where
);
1792 if (!scalar_check (event
, 0))
1795 if (!gfc_check_vardef_context (count
, false, false, false, NULL
))
1797 gfc_error ("COUNT argument of the EVENT_QUERY intrinsic function at %L "
1798 "shall be definable", &count
->where
);
1802 if (!type_check (count
, 1, BT_INTEGER
))
1805 int i
= gfc_validate_kind (BT_INTEGER
, count
->ts
.kind
, false);
1806 int j
= gfc_validate_kind (BT_INTEGER
, gfc_default_integer_kind
, false);
1808 if (gfc_integer_kinds
[i
].range
< gfc_integer_kinds
[j
].range
)
1810 gfc_error ("COUNT argument of the EVENT_QUERY intrinsic function at %L "
1811 "shall have at least the range of the default integer",
1818 if (!type_check (stat
, 2, BT_INTEGER
))
1820 if (!scalar_check (stat
, 2))
1822 if (!variable_check (stat
, 2, false))
1825 if (!gfc_notify_std (GFC_STD_F2018
, "STAT= argument to %s at %L",
1826 gfc_current_intrinsic
, &stat
->where
))
1835 gfc_check_atomic_fetch_op (gfc_expr
*atom
, gfc_expr
*value
, gfc_expr
*old
,
1838 if (atom
->expr_type
== EXPR_FUNCTION
1839 && atom
->value
.function
.isym
1840 && atom
->value
.function
.isym
->id
== GFC_ISYM_CAF_GET
)
1841 atom
= atom
->value
.function
.actual
->expr
;
1843 if (atom
->ts
.type
!= BT_INTEGER
|| atom
->ts
.kind
!= gfc_atomic_int_kind
)
1845 gfc_error ("ATOM argument at %L to intrinsic function %s shall be an "
1846 "integer of ATOMIC_INT_KIND", &atom
->where
,
1847 gfc_current_intrinsic
);
1851 if (!gfc_check_atomic (atom
, 0, value
, 1, stat
, 3))
1854 if (!scalar_check (old
, 2))
1857 if (!same_type_check (atom
, 0, old
, 2))
1860 if (!gfc_check_vardef_context (atom
, false, false, false, NULL
))
1862 gfc_error ("ATOM argument of the %s intrinsic function at %L shall be "
1863 "definable", gfc_current_intrinsic
, &atom
->where
);
1867 if (!gfc_check_vardef_context (old
, false, false, false, NULL
))
1869 gfc_error ("OLD argument of the %s intrinsic function at %L shall be "
1870 "definable", gfc_current_intrinsic
, &old
->where
);
1878 /* BESJN and BESYN functions. */
1881 gfc_check_besn (gfc_expr
*n
, gfc_expr
*x
)
1883 if (!type_check (n
, 0, BT_INTEGER
))
1885 if (n
->expr_type
== EXPR_CONSTANT
)
1888 gfc_extract_int (n
, &i
);
1889 if (i
< 0 && !gfc_notify_std (GFC_STD_GNU
, "Negative argument "
1890 "N at %L", &n
->where
))
1894 if (!type_check (x
, 1, BT_REAL
))
1901 /* Transformational version of the Bessel JN and YN functions. */
1904 gfc_check_bessel_n2 (gfc_expr
*n1
, gfc_expr
*n2
, gfc_expr
*x
)
1906 if (!type_check (n1
, 0, BT_INTEGER
))
1908 if (!scalar_check (n1
, 0))
1910 if (!nonnegative_check ("N1", n1
))
1913 if (!type_check (n2
, 1, BT_INTEGER
))
1915 if (!scalar_check (n2
, 1))
1917 if (!nonnegative_check ("N2", n2
))
1920 if (!type_check (x
, 2, BT_REAL
))
1922 if (!scalar_check (x
, 2))
1930 gfc_check_bge_bgt_ble_blt (gfc_expr
*i
, gfc_expr
*j
)
1932 extern int gfc_max_integer_kind
;
1934 /* If i and j are both BOZ, convert to widest INTEGER. */
1935 if (i
->ts
.type
== BT_BOZ
&& j
->ts
.type
== BT_BOZ
)
1937 if (!gfc_boz2int (i
, gfc_max_integer_kind
))
1939 if (!gfc_boz2int (j
, gfc_max_integer_kind
))
1943 /* If i is BOZ and j is integer, convert i to type of j. */
1944 if (i
->ts
.type
== BT_BOZ
&& j
->ts
.type
== BT_INTEGER
1945 && !gfc_boz2int (i
, j
->ts
.kind
))
1948 /* If j is BOZ and i is integer, convert j to type of i. */
1949 if (j
->ts
.type
== BT_BOZ
&& i
->ts
.type
== BT_INTEGER
1950 && !gfc_boz2int (j
, i
->ts
.kind
))
1953 if (!type_check (i
, 0, BT_INTEGER
))
1956 if (!type_check (j
, 1, BT_INTEGER
))
1964 gfc_check_bitfcn (gfc_expr
*i
, gfc_expr
*pos
)
1966 if (!type_check (i
, 0, BT_INTEGER
))
1969 if (!type_check (pos
, 1, BT_INTEGER
))
1972 if (!nonnegative_check ("pos", pos
))
1975 if (!less_than_bitsize1 ("i", i
, "pos", pos
, false))
1983 gfc_check_char (gfc_expr
*i
, gfc_expr
*kind
)
1985 if (i
->ts
.type
== BT_BOZ
)
1987 if (gfc_invalid_boz (G_("BOZ literal constant at %L cannot appear in "
1988 "CHAR intrinsic subprogram"), &i
->where
))
1991 if (!gfc_boz2int (i
, gfc_default_integer_kind
))
1995 if (!type_check (i
, 0, BT_INTEGER
))
1998 if (!kind_check (kind
, 1, BT_CHARACTER
))
2006 gfc_check_chdir (gfc_expr
*dir
)
2008 if (!type_check (dir
, 0, BT_CHARACTER
))
2010 if (!kind_value_check (dir
, 0, gfc_default_character_kind
))
2018 gfc_check_chdir_sub (gfc_expr
*dir
, gfc_expr
*status
)
2020 if (!type_check (dir
, 0, BT_CHARACTER
))
2022 if (!kind_value_check (dir
, 0, gfc_default_character_kind
))
2028 if (!type_check (status
, 1, BT_INTEGER
))
2030 if (!scalar_check (status
, 1))
2038 gfc_check_chmod (gfc_expr
*name
, gfc_expr
*mode
)
2040 if (!type_check (name
, 0, BT_CHARACTER
))
2042 if (!kind_value_check (name
, 0, gfc_default_character_kind
))
2045 if (!type_check (mode
, 1, BT_CHARACTER
))
2047 if (!kind_value_check (mode
, 1, gfc_default_character_kind
))
2055 gfc_check_chmod_sub (gfc_expr
*name
, gfc_expr
*mode
, gfc_expr
*status
)
2057 if (!type_check (name
, 0, BT_CHARACTER
))
2059 if (!kind_value_check (name
, 0, gfc_default_character_kind
))
2062 if (!type_check (mode
, 1, BT_CHARACTER
))
2064 if (!kind_value_check (mode
, 1, gfc_default_character_kind
))
2070 if (!type_check (status
, 2, BT_INTEGER
))
2073 if (!scalar_check (status
, 2))
2081 gfc_check_cmplx (gfc_expr
*x
, gfc_expr
*y
, gfc_expr
*kind
)
2085 /* Check kind first, because it may be needed in conversion of a BOZ. */
2088 if (!kind_check (kind
, 2, BT_COMPLEX
))
2090 gfc_extract_int (kind
, &k
);
2093 k
= gfc_default_complex_kind
;
2095 if (x
->ts
.type
== BT_BOZ
&& !gfc_boz2real (x
, k
))
2098 if (!numeric_check (x
, 0))
2103 if (y
->ts
.type
== BT_BOZ
&& !gfc_boz2real (y
, k
))
2106 if (!numeric_check (y
, 1))
2109 if (x
->ts
.type
== BT_COMPLEX
)
2111 gfc_error ("%qs argument of %qs intrinsic at %L must not be "
2112 "present if %<x%> is COMPLEX",
2113 gfc_current_intrinsic_arg
[1]->name
, gfc_current_intrinsic
,
2118 if (y
->ts
.type
== BT_COMPLEX
)
2120 gfc_error ("%qs argument of %qs intrinsic at %L must have a type "
2121 "of either REAL or INTEGER",
2122 gfc_current_intrinsic_arg
[1]->name
, gfc_current_intrinsic
,
2128 if (!kind
&& warn_conversion
2129 && x
->ts
.type
== BT_REAL
&& x
->ts
.kind
> gfc_default_real_kind
)
2130 gfc_warning_now (OPT_Wconversion
, "Conversion from %s to default-kind "
2131 "COMPLEX(%d) at %L might lose precision, consider using "
2132 "the KIND argument", gfc_typename (&x
->ts
),
2133 gfc_default_real_kind
, &x
->where
);
2134 else if (y
&& !kind
&& warn_conversion
2135 && y
->ts
.type
== BT_REAL
&& y
->ts
.kind
> gfc_default_real_kind
)
2136 gfc_warning_now (OPT_Wconversion
, "Conversion from %s to default-kind "
2137 "COMPLEX(%d) at %L might lose precision, consider using "
2138 "the KIND argument", gfc_typename (&y
->ts
),
2139 gfc_default_real_kind
, &y
->where
);
2145 check_co_collective (gfc_expr
*a
, gfc_expr
*image_idx
, gfc_expr
*stat
,
2146 gfc_expr
*errmsg
, bool co_reduce
)
2148 if (!variable_check (a
, 0, false))
2151 if (!gfc_check_vardef_context (a
, false, false, false, "argument 'A' with "
2155 /* Fortran 2008, 12.5.2.4, paragraph 18. */
2156 if (gfc_has_vector_subscript (a
))
2158 gfc_error ("Argument %<A%> with INTENT(INOUT) at %L of the intrinsic "
2159 "subroutine %s shall not have a vector subscript",
2160 &a
->where
, gfc_current_intrinsic
);
2164 if (gfc_is_coindexed (a
))
2166 gfc_error ("The A argument at %L to the intrinsic %s shall not be "
2167 "coindexed", &a
->where
, gfc_current_intrinsic
);
2171 if (image_idx
!= NULL
)
2173 if (!type_check (image_idx
, co_reduce
? 2 : 1, BT_INTEGER
))
2175 if (!scalar_check (image_idx
, co_reduce
? 2 : 1))
2181 if (!type_check (stat
, co_reduce
? 3 : 2, BT_INTEGER
))
2183 if (!scalar_check (stat
, co_reduce
? 3 : 2))
2185 if (!variable_check (stat
, co_reduce
? 3 : 2, false))
2187 if (stat
->ts
.kind
!= 4)
2189 gfc_error ("The stat= argument at %L must be a kind=4 integer "
2190 "variable", &stat
->where
);
2197 if (!type_check (errmsg
, co_reduce
? 4 : 3, BT_CHARACTER
))
2199 if (!scalar_check (errmsg
, co_reduce
? 4 : 3))
2201 if (!variable_check (errmsg
, co_reduce
? 4 : 3, false))
2203 if (errmsg
->ts
.kind
!= 1)
2205 gfc_error ("The errmsg= argument at %L must be a default-kind "
2206 "character variable", &errmsg
->where
);
2211 if (flag_coarray
== GFC_FCOARRAY_NONE
)
2213 gfc_fatal_error ("Coarrays disabled at %L, use %<-fcoarray=%> to enable",
2223 gfc_check_co_broadcast (gfc_expr
*a
, gfc_expr
*source_image
, gfc_expr
*stat
,
2226 if (a
->ts
.type
== BT_CLASS
|| gfc_expr_attr (a
).alloc_comp
)
2228 gfc_error ("Support for the A argument at %L which is polymorphic A "
2229 "argument or has allocatable components is not yet "
2230 "implemented", &a
->where
);
2233 return check_co_collective (a
, source_image
, stat
, errmsg
, false);
2238 gfc_check_co_reduce (gfc_expr
*a
, gfc_expr
*op
, gfc_expr
*result_image
,
2239 gfc_expr
*stat
, gfc_expr
*errmsg
)
2241 symbol_attribute attr
;
2242 gfc_formal_arglist
*formal
;
2245 if (a
->ts
.type
== BT_CLASS
)
2247 gfc_error ("The A argument at %L of CO_REDUCE shall not be polymorphic",
2252 if (gfc_expr_attr (a
).alloc_comp
)
2254 gfc_error ("Support for the A argument at %L with allocatable components"
2255 " is not yet implemented", &a
->where
);
2259 if (!check_co_collective (a
, result_image
, stat
, errmsg
, true))
2262 if (!gfc_resolve_expr (op
))
2265 attr
= gfc_expr_attr (op
);
2266 if (!attr
.pure
|| !attr
.function
)
2268 gfc_error ("OPERATION argument at %L must be a PURE function",
2275 /* None of the intrinsics fulfills the criteria of taking two arguments,
2276 returning the same type and kind as the arguments and being permitted
2277 as actual argument. */
2278 gfc_error ("Intrinsic function %s at %L is not permitted for CO_REDUCE",
2279 op
->symtree
->n
.sym
->name
, &op
->where
);
2283 if (gfc_is_proc_ptr_comp (op
))
2285 gfc_component
*comp
= gfc_get_proc_ptr_comp (op
);
2286 sym
= comp
->ts
.interface
;
2289 sym
= op
->symtree
->n
.sym
;
2291 formal
= sym
->formal
;
2293 if (!formal
|| !formal
->next
|| formal
->next
->next
)
2295 gfc_error ("The function passed as OPERATION at %L shall have two "
2296 "arguments", &op
->where
);
2300 if (sym
->result
->ts
.type
== BT_UNKNOWN
)
2301 gfc_set_default_type (sym
->result
, 0, NULL
);
2303 if (!gfc_compare_types (&a
->ts
, &sym
->result
->ts
))
2305 gfc_error ("The A argument at %L has type %s but the function passed as "
2306 "OPERATION at %L returns %s",
2307 &a
->where
, gfc_typename (a
), &op
->where
,
2308 gfc_typename (&sym
->result
->ts
));
2311 if (!gfc_compare_types (&a
->ts
, &formal
->sym
->ts
)
2312 || !gfc_compare_types (&a
->ts
, &formal
->next
->sym
->ts
))
2314 gfc_error ("The function passed as OPERATION at %L has arguments of type "
2315 "%s and %s but shall have type %s", &op
->where
,
2316 gfc_typename (&formal
->sym
->ts
),
2317 gfc_typename (&formal
->next
->sym
->ts
), gfc_typename (a
));
2320 if (op
->rank
|| attr
.allocatable
|| attr
.pointer
|| formal
->sym
->as
2321 || formal
->next
->sym
->as
|| formal
->sym
->attr
.allocatable
2322 || formal
->next
->sym
->attr
.allocatable
|| formal
->sym
->attr
.pointer
2323 || formal
->next
->sym
->attr
.pointer
)
2325 gfc_error ("The function passed as OPERATION at %L shall have scalar "
2326 "nonallocatable nonpointer arguments and return a "
2327 "nonallocatable nonpointer scalar", &op
->where
);
2331 if (formal
->sym
->attr
.value
!= formal
->next
->sym
->attr
.value
)
2333 gfc_error ("The function passed as OPERATION at %L shall have the VALUE "
2334 "attribute either for none or both arguments", &op
->where
);
2338 if (formal
->sym
->attr
.target
!= formal
->next
->sym
->attr
.target
)
2340 gfc_error ("The function passed as OPERATION at %L shall have the TARGET "
2341 "attribute either for none or both arguments", &op
->where
);
2345 if (formal
->sym
->attr
.asynchronous
!= formal
->next
->sym
->attr
.asynchronous
)
2347 gfc_error ("The function passed as OPERATION at %L shall have the "
2348 "ASYNCHRONOUS attribute either for none or both arguments",
2353 if (formal
->sym
->attr
.optional
|| formal
->next
->sym
->attr
.optional
)
2355 gfc_error ("The function passed as OPERATION at %L shall not have the "
2356 "OPTIONAL attribute for either of the arguments", &op
->where
);
2360 if (a
->ts
.type
== BT_CHARACTER
)
2363 unsigned long actual_size
, formal_size1
, formal_size2
, result_size
;
2366 actual_size
= cl
&& cl
->length
&& cl
->length
->expr_type
== EXPR_CONSTANT
2367 ? mpz_get_ui (cl
->length
->value
.integer
) : 0;
2369 cl
= formal
->sym
->ts
.u
.cl
;
2370 formal_size1
= cl
&& cl
->length
&& cl
->length
->expr_type
== EXPR_CONSTANT
2371 ? mpz_get_ui (cl
->length
->value
.integer
) : 0;
2373 cl
= formal
->next
->sym
->ts
.u
.cl
;
2374 formal_size2
= cl
&& cl
->length
&& cl
->length
->expr_type
== EXPR_CONSTANT
2375 ? mpz_get_ui (cl
->length
->value
.integer
) : 0;
2378 result_size
= cl
&& cl
->length
&& cl
->length
->expr_type
== EXPR_CONSTANT
2379 ? mpz_get_ui (cl
->length
->value
.integer
) : 0;
2382 && ((formal_size1
&& actual_size
!= formal_size1
)
2383 || (formal_size2
&& actual_size
!= formal_size2
)))
2385 gfc_error ("The character length of the A argument at %L and of the "
2386 "arguments of the OPERATION at %L shall be the same",
2387 &a
->where
, &op
->where
);
2390 if (actual_size
&& result_size
&& actual_size
!= result_size
)
2392 gfc_error ("The character length of the A argument at %L and of the "
2393 "function result of the OPERATION at %L shall be the same",
2394 &a
->where
, &op
->where
);
2404 gfc_check_co_minmax (gfc_expr
*a
, gfc_expr
*result_image
, gfc_expr
*stat
,
2407 if (a
->ts
.type
!= BT_INTEGER
&& a
->ts
.type
!= BT_REAL
2408 && a
->ts
.type
!= BT_CHARACTER
)
2410 gfc_error ("%qs argument of %qs intrinsic at %L shall be of type "
2411 "integer, real or character",
2412 gfc_current_intrinsic_arg
[0]->name
, gfc_current_intrinsic
,
2416 return check_co_collective (a
, result_image
, stat
, errmsg
, false);
2421 gfc_check_co_sum (gfc_expr
*a
, gfc_expr
*result_image
, gfc_expr
*stat
,
2424 if (!numeric_check (a
, 0))
2426 return check_co_collective (a
, result_image
, stat
, errmsg
, false);
2431 gfc_check_complex (gfc_expr
*x
, gfc_expr
*y
)
2433 if (!boz_args_check (x
, y
))
2436 if (x
->ts
.type
== BT_BOZ
)
2438 if (gfc_invalid_boz (G_("BOZ constant at %L cannot appear in the COMPLEX"
2439 " intrinsic subprogram"), &x
->where
))
2444 if (y
->ts
.type
== BT_INTEGER
&& !gfc_boz2int (x
, y
->ts
.kind
))
2446 if (y
->ts
.type
== BT_REAL
&& !gfc_boz2real (x
, y
->ts
.kind
))
2450 if (y
->ts
.type
== BT_BOZ
)
2452 if (gfc_invalid_boz (G_("BOZ constant at %L cannot appear in the COMPLEX"
2453 " intrinsic subprogram"), &y
->where
))
2458 if (x
->ts
.type
== BT_INTEGER
&& !gfc_boz2int (y
, x
->ts
.kind
))
2460 if (x
->ts
.type
== BT_REAL
&& !gfc_boz2real (y
, x
->ts
.kind
))
2464 if (!int_or_real_check (x
, 0))
2466 if (!scalar_check (x
, 0))
2469 if (!int_or_real_check (y
, 1))
2471 if (!scalar_check (y
, 1))
2479 gfc_check_count (gfc_expr
*mask
, gfc_expr
*dim
, gfc_expr
*kind
)
2481 if (!logical_array_check (mask
, 0))
2483 if (!dim_check (dim
, 1, false))
2485 if (!dim_rank_check (dim
, mask
, 0))
2487 if (!kind_check (kind
, 2, BT_INTEGER
))
2489 if (kind
&& !gfc_notify_std (GFC_STD_F2003
, "%qs intrinsic "
2490 "with KIND argument at %L",
2491 gfc_current_intrinsic
, &kind
->where
))
2499 gfc_check_cshift (gfc_expr
*array
, gfc_expr
*shift
, gfc_expr
*dim
)
2501 if (!array_check (array
, 0))
2504 if (!type_check (shift
, 1, BT_INTEGER
))
2507 if (!dim_check (dim
, 2, true))
2510 if (!dim_rank_check (dim
, array
, false))
2513 if (array
->rank
== 1 || shift
->rank
== 0)
2515 if (!scalar_check (shift
, 1))
2518 else if (shift
->rank
== array
->rank
- 1)
2523 else if (dim
->expr_type
== EXPR_CONSTANT
)
2524 gfc_extract_int (dim
, &d
);
2531 for (i
= 0, j
= 0; i
< array
->rank
; i
++)
2534 if (!identical_dimen_shape (array
, i
, shift
, j
))
2536 gfc_error ("%qs argument of %qs intrinsic at %L has "
2537 "invalid shape in dimension %d (%ld/%ld)",
2538 gfc_current_intrinsic_arg
[1]->name
,
2539 gfc_current_intrinsic
, &shift
->where
, i
+ 1,
2540 mpz_get_si (array
->shape
[i
]),
2541 mpz_get_si (shift
->shape
[j
]));
2551 gfc_error ("%qs argument of intrinsic %qs at %L of must have rank "
2552 "%d or be a scalar", gfc_current_intrinsic_arg
[1]->name
,
2553 gfc_current_intrinsic
, &shift
->where
, array
->rank
- 1);
2562 gfc_check_ctime (gfc_expr
*time
)
2564 if (!scalar_check (time
, 0))
2567 if (!type_check (time
, 0, BT_INTEGER
))
2574 bool gfc_check_datan2 (gfc_expr
*y
, gfc_expr
*x
)
2576 if (!double_check (y
, 0) || !double_check (x
, 1))
2583 gfc_check_dcmplx (gfc_expr
*x
, gfc_expr
*y
)
2585 if (x
->ts
.type
== BT_BOZ
&& !gfc_boz2real (x
, gfc_default_double_kind
))
2588 if (!numeric_check (x
, 0))
2593 if (y
->ts
.type
== BT_BOZ
&& !gfc_boz2real (y
, gfc_default_double_kind
))
2596 if (!numeric_check (y
, 1))
2599 if (x
->ts
.type
== BT_COMPLEX
)
2601 gfc_error ("%qs argument of %qs intrinsic at %L must not be "
2602 "present if %<x%> is COMPLEX",
2603 gfc_current_intrinsic_arg
[1]->name
, gfc_current_intrinsic
,
2608 if (y
->ts
.type
== BT_COMPLEX
)
2610 gfc_error ("%qs argument of %qs intrinsic at %L must have a type "
2611 "of either REAL or INTEGER",
2612 gfc_current_intrinsic_arg
[1]->name
, gfc_current_intrinsic
,
2623 gfc_check_dble (gfc_expr
*x
)
2625 if (x
->ts
.type
== BT_BOZ
&& !gfc_boz2real (x
, gfc_default_double_kind
))
2628 if (!numeric_check (x
, 0))
2636 gfc_check_digits (gfc_expr
*x
)
2638 if (!int_or_real_check (x
, 0))
2646 gfc_check_dot_product (gfc_expr
*vector_a
, gfc_expr
*vector_b
)
2648 switch (vector_a
->ts
.type
)
2651 if (!type_check (vector_b
, 1, BT_LOGICAL
))
2658 if (!numeric_check (vector_b
, 1))
2663 gfc_error ("%qs argument of %qs intrinsic at %L must be numeric "
2664 "or LOGICAL", gfc_current_intrinsic_arg
[0]->name
,
2665 gfc_current_intrinsic
, &vector_a
->where
);
2669 if (!rank_check (vector_a
, 0, 1))
2672 if (!rank_check (vector_b
, 1, 1))
2675 if (! identical_dimen_shape (vector_a
, 0, vector_b
, 0))
2677 gfc_error ("Different shape for arguments %qs and %qs at %L for "
2678 "intrinsic %<dot_product%>",
2679 gfc_current_intrinsic_arg
[0]->name
,
2680 gfc_current_intrinsic_arg
[1]->name
, &vector_a
->where
);
2689 gfc_check_dprod (gfc_expr
*x
, gfc_expr
*y
)
2691 if (!type_check (x
, 0, BT_REAL
)
2692 || !type_check (y
, 1, BT_REAL
))
2695 if (x
->ts
.kind
!= gfc_default_real_kind
)
2697 gfc_error ("%qs argument of %qs intrinsic at %L must be default "
2698 "real", gfc_current_intrinsic_arg
[0]->name
,
2699 gfc_current_intrinsic
, &x
->where
);
2703 if (y
->ts
.kind
!= gfc_default_real_kind
)
2705 gfc_error ("%qs argument of %qs intrinsic at %L must be default "
2706 "real", gfc_current_intrinsic_arg
[1]->name
,
2707 gfc_current_intrinsic
, &y
->where
);
2715 gfc_check_dshift (gfc_expr
*i
, gfc_expr
*j
, gfc_expr
*shift
)
2717 /* i and j cannot both be BOZ literal constants. */
2718 if (!boz_args_check (i
, j
))
2721 /* If i is BOZ and j is integer, convert i to type of j. If j is not
2722 an integer, clear the BOZ; otherwise, check that i is an integer. */
2723 if (i
->ts
.type
== BT_BOZ
)
2725 if (j
->ts
.type
!= BT_INTEGER
)
2727 else if (!gfc_boz2int (i
, j
->ts
.kind
))
2730 else if (!type_check (i
, 0, BT_INTEGER
))
2732 if (j
->ts
.type
== BT_BOZ
)
2737 /* If j is BOZ and i is integer, convert j to type of i. If i is not
2738 an integer, clear the BOZ; otherwise, check that i is an integer. */
2739 if (j
->ts
.type
== BT_BOZ
)
2741 if (i
->ts
.type
!= BT_INTEGER
)
2743 else if (!gfc_boz2int (j
, i
->ts
.kind
))
2746 else if (!type_check (j
, 1, BT_INTEGER
))
2749 if (!same_type_check (i
, 0, j
, 1))
2752 if (!type_check (shift
, 2, BT_INTEGER
))
2755 if (!nonnegative_check ("SHIFT", shift
))
2758 if (!less_than_bitsize1 ("I", i
, "SHIFT", shift
, true))
2766 gfc_check_eoshift (gfc_expr
*array
, gfc_expr
*shift
, gfc_expr
*boundary
,
2771 if (!array_check (array
, 0))
2774 if (!type_check (shift
, 1, BT_INTEGER
))
2777 if (!dim_check (dim
, 3, true))
2780 if (!dim_rank_check (dim
, array
, false))
2785 else if (dim
->expr_type
== EXPR_CONSTANT
)
2786 gfc_extract_int (dim
, &d
);
2790 if (array
->rank
== 1 || shift
->rank
== 0)
2792 if (!scalar_check (shift
, 1))
2795 else if (shift
->rank
== array
->rank
- 1)
2800 for (i
= 0, j
= 0; i
< array
->rank
; i
++)
2803 if (!identical_dimen_shape (array
, i
, shift
, j
))
2805 gfc_error ("%qs argument of %qs intrinsic at %L has "
2806 "invalid shape in dimension %d (%ld/%ld)",
2807 gfc_current_intrinsic_arg
[1]->name
,
2808 gfc_current_intrinsic
, &shift
->where
, i
+ 1,
2809 mpz_get_si (array
->shape
[i
]),
2810 mpz_get_si (shift
->shape
[j
]));
2820 gfc_error ("%qs argument of intrinsic %qs at %L of must have rank "
2821 "%d or be a scalar", gfc_current_intrinsic_arg
[1]->name
,
2822 gfc_current_intrinsic
, &shift
->where
, array
->rank
- 1);
2826 if (boundary
!= NULL
)
2828 if (!same_type_check (array
, 0, boundary
, 2))
2831 /* Reject unequal string lengths and emit a better error message than
2832 gfc_check_same_strlen would. */
2833 if (array
->ts
.type
== BT_CHARACTER
)
2835 ssize_t len_a
, len_b
;
2837 len_a
= gfc_var_strlen (array
);
2838 len_b
= gfc_var_strlen (boundary
);
2839 if (len_a
!= -1 && len_b
!= -1 && len_a
!= len_b
)
2841 gfc_error ("%qs must be of same type and kind as %qs at %L in %qs",
2842 gfc_current_intrinsic_arg
[2]->name
,
2843 gfc_current_intrinsic_arg
[0]->name
,
2844 &boundary
->where
, gfc_current_intrinsic
);
2849 if (array
->rank
== 1 || boundary
->rank
== 0)
2851 if (!scalar_check (boundary
, 2))
2854 else if (boundary
->rank
== array
->rank
- 1)
2859 for (i
= 0, j
= 0; i
< array
->rank
; i
++)
2863 if (!identical_dimen_shape (array
, i
, boundary
, j
))
2865 gfc_error ("%qs argument of %qs intrinsic at %L has "
2866 "invalid shape in dimension %d (%ld/%ld)",
2867 gfc_current_intrinsic_arg
[2]->name
,
2868 gfc_current_intrinsic
, &shift
->where
, i
+1,
2869 mpz_get_si (array
->shape
[i
]),
2870 mpz_get_si (boundary
->shape
[j
]));
2880 gfc_error ("%qs argument of intrinsic %qs at %L of must have "
2881 "rank %d or be a scalar",
2882 gfc_current_intrinsic_arg
[1]->name
, gfc_current_intrinsic
,
2883 &shift
->where
, array
->rank
- 1);
2889 switch (array
->ts
.type
)
2899 gfc_error ("Missing %qs argument to %qs intrinsic at %L for %qs "
2900 "of type %qs", gfc_current_intrinsic_arg
[2]->name
,
2901 gfc_current_intrinsic
, &array
->where
,
2902 gfc_current_intrinsic_arg
[0]->name
,
2903 gfc_typename (array
));
2913 gfc_check_float (gfc_expr
*a
)
2915 if (a
->ts
.type
== BT_BOZ
)
2917 if (gfc_invalid_boz (G_("BOZ literal constant at %L cannot appear in the"
2918 " FLOAT intrinsic subprogram"), &a
->where
))
2923 if (!gfc_boz2int (a
, gfc_default_integer_kind
))
2927 if (!type_check (a
, 0, BT_INTEGER
))
2930 if ((a
->ts
.kind
!= gfc_default_integer_kind
)
2931 && !gfc_notify_std (GFC_STD_GNU
, "non-default INTEGER "
2932 "kind argument to %s intrinsic at %L",
2933 gfc_current_intrinsic
, &a
->where
))
2939 /* A single complex argument. */
2942 gfc_check_fn_c (gfc_expr
*a
)
2944 if (!type_check (a
, 0, BT_COMPLEX
))
2951 /* A single real argument. */
2954 gfc_check_fn_r (gfc_expr
*a
)
2956 if (!type_check (a
, 0, BT_REAL
))
2962 /* A single double argument. */
2965 gfc_check_fn_d (gfc_expr
*a
)
2967 if (!double_check (a
, 0))
2973 /* A single real or complex argument. */
2976 gfc_check_fn_rc (gfc_expr
*a
)
2978 if (!real_or_complex_check (a
, 0))
2986 gfc_check_fn_rc2008 (gfc_expr
*a
)
2988 if (!real_or_complex_check (a
, 0))
2991 if (a
->ts
.type
== BT_COMPLEX
2992 && !gfc_notify_std (GFC_STD_F2008
, "COMPLEX argument %qs "
2993 "of %qs intrinsic at %L",
2994 gfc_current_intrinsic_arg
[0]->name
,
2995 gfc_current_intrinsic
, &a
->where
))
3003 gfc_check_fnum (gfc_expr
*unit
)
3005 if (!type_check (unit
, 0, BT_INTEGER
))
3008 if (!scalar_check (unit
, 0))
3016 gfc_check_huge (gfc_expr
*x
)
3018 if (!int_or_real_check (x
, 0))
3026 gfc_check_hypot (gfc_expr
*x
, gfc_expr
*y
)
3028 if (!type_check (x
, 0, BT_REAL
))
3030 if (!same_type_check (x
, 0, y
, 1))
3037 /* Check that the single argument is an integer. */
3040 gfc_check_i (gfc_expr
*i
)
3042 if (!type_check (i
, 0, BT_INTEGER
))
3050 gfc_check_iand_ieor_ior (gfc_expr
*i
, gfc_expr
*j
)
3052 /* i and j cannot both be BOZ literal constants. */
3053 if (!boz_args_check (i
, j
))
3056 /* If i is BOZ and j is integer, convert i to type of j. */
3057 if (i
->ts
.type
== BT_BOZ
&& j
->ts
.type
== BT_INTEGER
3058 && !gfc_boz2int (i
, j
->ts
.kind
))
3061 /* If j is BOZ and i is integer, convert j to type of i. */
3062 if (j
->ts
.type
== BT_BOZ
&& i
->ts
.type
== BT_INTEGER
3063 && !gfc_boz2int (j
, i
->ts
.kind
))
3066 if (!type_check (i
, 0, BT_INTEGER
))
3069 if (!type_check (j
, 1, BT_INTEGER
))
3072 if (i
->ts
.kind
!= j
->ts
.kind
)
3074 gfc_error ("Arguments of %qs have different kind type parameters "
3075 "at %L", gfc_current_intrinsic
, &i
->where
);
3084 gfc_check_ibits (gfc_expr
*i
, gfc_expr
*pos
, gfc_expr
*len
)
3086 if (!type_check (i
, 0, BT_INTEGER
))
3089 if (!type_check (pos
, 1, BT_INTEGER
))
3092 if (!type_check (len
, 2, BT_INTEGER
))
3095 if (!nonnegative_check ("pos", pos
))
3098 if (!nonnegative_check ("len", len
))
3101 if (!less_than_bitsize2 ("i", i
, "pos", pos
, "len", len
))
3109 gfc_check_ichar_iachar (gfc_expr
*c
, gfc_expr
*kind
)
3113 if (!type_check (c
, 0, BT_CHARACTER
))
3116 if (!kind_check (kind
, 1, BT_INTEGER
))
3119 if (kind
&& !gfc_notify_std (GFC_STD_F2003
, "%qs intrinsic "
3120 "with KIND argument at %L",
3121 gfc_current_intrinsic
, &kind
->where
))
3124 if (c
->expr_type
== EXPR_VARIABLE
|| c
->expr_type
== EXPR_SUBSTRING
)
3130 /* Substring references don't have the charlength set. */
3132 while (ref
&& ref
->type
!= REF_SUBSTRING
)
3135 gcc_assert (ref
== NULL
|| ref
->type
== REF_SUBSTRING
);
3139 /* Check that the argument is length one. Non-constant lengths
3140 can't be checked here, so assume they are ok. */
3141 if (c
->ts
.u
.cl
&& c
->ts
.u
.cl
->length
)
3143 /* If we already have a length for this expression then use it. */
3144 if (c
->ts
.u
.cl
->length
->expr_type
!= EXPR_CONSTANT
)
3146 i
= mpz_get_si (c
->ts
.u
.cl
->length
->value
.integer
);
3153 start
= ref
->u
.ss
.start
;
3154 end
= ref
->u
.ss
.end
;
3157 if (end
== NULL
|| end
->expr_type
!= EXPR_CONSTANT
3158 || start
->expr_type
!= EXPR_CONSTANT
)
3161 i
= mpz_get_si (end
->value
.integer
) + 1
3162 - mpz_get_si (start
->value
.integer
);
3170 gfc_error ("Argument of %s at %L must be of length one",
3171 gfc_current_intrinsic
, &c
->where
);
3180 gfc_check_idnint (gfc_expr
*a
)
3182 if (!double_check (a
, 0))
3190 gfc_check_index (gfc_expr
*string
, gfc_expr
*substring
, gfc_expr
*back
,
3193 if (!type_check (string
, 0, BT_CHARACTER
)
3194 || !type_check (substring
, 1, BT_CHARACTER
))
3197 if (back
!= NULL
&& !type_check (back
, 2, BT_LOGICAL
))
3200 if (!kind_check (kind
, 3, BT_INTEGER
))
3202 if (kind
&& !gfc_notify_std (GFC_STD_F2003
, "%qs intrinsic "
3203 "with KIND argument at %L",
3204 gfc_current_intrinsic
, &kind
->where
))
3207 if (string
->ts
.kind
!= substring
->ts
.kind
)
3209 gfc_error ("%qs argument of %qs intrinsic at %L must be the same "
3210 "kind as %qs", gfc_current_intrinsic_arg
[1]->name
,
3211 gfc_current_intrinsic
, &substring
->where
,
3212 gfc_current_intrinsic_arg
[0]->name
);
3221 gfc_check_int (gfc_expr
*x
, gfc_expr
*kind
)
3223 /* BOZ is dealt within simplify_int*. */
3224 if (x
->ts
.type
== BT_BOZ
)
3227 if (!numeric_check (x
, 0))
3230 if (!kind_check (kind
, 1, BT_INTEGER
))
3238 gfc_check_intconv (gfc_expr
*x
)
3240 if (strcmp (gfc_current_intrinsic
, "short") == 0
3241 || strcmp (gfc_current_intrinsic
, "long") == 0)
3243 gfc_error ("%qs intrinsic subprogram at %L has been removed. "
3244 "Use INT intrinsic subprogram.", gfc_current_intrinsic
,
3249 /* BOZ is dealt within simplify_int*. */
3250 if (x
->ts
.type
== BT_BOZ
)
3253 if (!numeric_check (x
, 0))
3260 gfc_check_ishft (gfc_expr
*i
, gfc_expr
*shift
)
3262 if (!type_check (i
, 0, BT_INTEGER
)
3263 || !type_check (shift
, 1, BT_INTEGER
))
3266 if (!less_than_bitsize1 ("I", i
, NULL
, shift
, true))
3274 gfc_check_ishftc (gfc_expr
*i
, gfc_expr
*shift
, gfc_expr
*size
)
3276 if (!type_check (i
, 0, BT_INTEGER
)
3277 || !type_check (shift
, 1, BT_INTEGER
))
3284 if (!type_check (size
, 2, BT_INTEGER
))
3287 if (!less_than_bitsize1 ("I", i
, "SIZE", size
, true))
3290 if (size
->expr_type
== EXPR_CONSTANT
)
3292 gfc_extract_int (size
, &i3
);
3295 gfc_error ("SIZE at %L must be positive", &size
->where
);
3299 if (shift
->expr_type
== EXPR_CONSTANT
)
3301 gfc_extract_int (shift
, &i2
);
3307 gfc_error ("The absolute value of SHIFT at %L must be less "
3308 "than or equal to SIZE at %L", &shift
->where
,
3315 else if (!less_than_bitsize1 ("I", i
, NULL
, shift
, true))
3323 gfc_check_kill (gfc_expr
*pid
, gfc_expr
*sig
)
3325 if (!type_check (pid
, 0, BT_INTEGER
))
3328 if (!scalar_check (pid
, 0))
3331 if (!type_check (sig
, 1, BT_INTEGER
))
3334 if (!scalar_check (sig
, 1))
3342 gfc_check_kill_sub (gfc_expr
*pid
, gfc_expr
*sig
, gfc_expr
*status
)
3344 if (!type_check (pid
, 0, BT_INTEGER
))
3347 if (!scalar_check (pid
, 0))
3350 if (!type_check (sig
, 1, BT_INTEGER
))
3353 if (!scalar_check (sig
, 1))
3358 if (!type_check (status
, 2, BT_INTEGER
))
3361 if (!scalar_check (status
, 2))
3364 if (status
->expr_type
!= EXPR_VARIABLE
)
3366 gfc_error ("STATUS at %L shall be an INTENT(OUT) variable",
3371 if (status
->expr_type
== EXPR_VARIABLE
3372 && status
->symtree
&& status
->symtree
->n
.sym
3373 && status
->symtree
->n
.sym
->attr
.intent
== INTENT_IN
)
3375 gfc_error ("%qs at %L shall be an INTENT(OUT) variable",
3376 status
->symtree
->name
, &status
->where
);
3386 gfc_check_kind (gfc_expr
*x
)
3388 if (gfc_invalid_null_arg (x
))
3391 if (gfc_bt_struct (x
->ts
.type
) || x
->ts
.type
== BT_CLASS
)
3393 gfc_error ("%qs argument of %qs intrinsic at %L must be of "
3394 "intrinsic type", gfc_current_intrinsic_arg
[0]->name
,
3395 gfc_current_intrinsic
, &x
->where
);
3398 if (x
->ts
.type
== BT_PROCEDURE
)
3400 gfc_error ("%qs argument of %qs intrinsic at %L must be a data entity",
3401 gfc_current_intrinsic_arg
[0]->name
, gfc_current_intrinsic
,
3411 gfc_check_lbound (gfc_expr
*array
, gfc_expr
*dim
, gfc_expr
*kind
)
3413 if (!array_check (array
, 0))
3416 if (!dim_check (dim
, 1, false))
3419 if (!dim_rank_check (dim
, array
, 1))
3422 if (!kind_check (kind
, 2, BT_INTEGER
))
3424 if (kind
&& !gfc_notify_std (GFC_STD_F2003
, "%qs intrinsic "
3425 "with KIND argument at %L",
3426 gfc_current_intrinsic
, &kind
->where
))
3434 gfc_check_lcobound (gfc_expr
*coarray
, gfc_expr
*dim
, gfc_expr
*kind
)
3436 if (flag_coarray
== GFC_FCOARRAY_NONE
)
3438 gfc_fatal_error ("Coarrays disabled at %C, use %<-fcoarray=%> to enable");
3442 if (!coarray_check (coarray
, 0))
3447 if (!dim_check (dim
, 1, false))
3450 if (!dim_corank_check (dim
, coarray
))
3454 if (!kind_check (kind
, 2, BT_INTEGER
))
3462 gfc_check_len_lentrim (gfc_expr
*s
, gfc_expr
*kind
)
3464 if (!type_check (s
, 0, BT_CHARACTER
))
3467 if (gfc_invalid_null_arg (s
))
3470 if (!kind_check (kind
, 1, BT_INTEGER
))
3472 if (kind
&& !gfc_notify_std (GFC_STD_F2003
, "%qs intrinsic "
3473 "with KIND argument at %L",
3474 gfc_current_intrinsic
, &kind
->where
))
3482 gfc_check_lge_lgt_lle_llt (gfc_expr
*a
, gfc_expr
*b
)
3484 if (!type_check (a
, 0, BT_CHARACTER
))
3486 if (!kind_value_check (a
, 0, gfc_default_character_kind
))
3489 if (!type_check (b
, 1, BT_CHARACTER
))
3491 if (!kind_value_check (b
, 1, gfc_default_character_kind
))
3499 gfc_check_link (gfc_expr
*path1
, gfc_expr
*path2
)
3501 if (!type_check (path1
, 0, BT_CHARACTER
))
3503 if (!kind_value_check (path1
, 0, gfc_default_character_kind
))
3506 if (!type_check (path2
, 1, BT_CHARACTER
))
3508 if (!kind_value_check (path2
, 1, gfc_default_character_kind
))
3516 gfc_check_link_sub (gfc_expr
*path1
, gfc_expr
*path2
, gfc_expr
*status
)
3518 if (!type_check (path1
, 0, BT_CHARACTER
))
3520 if (!kind_value_check (path1
, 0, gfc_default_character_kind
))
3523 if (!type_check (path2
, 1, BT_CHARACTER
))
3525 if (!kind_value_check (path2
, 0, gfc_default_character_kind
))
3531 if (!type_check (status
, 2, BT_INTEGER
))
3534 if (!scalar_check (status
, 2))
3542 gfc_check_loc (gfc_expr
*expr
)
3544 return variable_check (expr
, 0, true);
3549 gfc_check_symlnk (gfc_expr
*path1
, gfc_expr
*path2
)
3551 if (!type_check (path1
, 0, BT_CHARACTER
))
3553 if (!kind_value_check (path1
, 0, gfc_default_character_kind
))
3556 if (!type_check (path2
, 1, BT_CHARACTER
))
3558 if (!kind_value_check (path2
, 1, gfc_default_character_kind
))
3566 gfc_check_symlnk_sub (gfc_expr
*path1
, gfc_expr
*path2
, gfc_expr
*status
)
3568 if (!type_check (path1
, 0, BT_CHARACTER
))
3570 if (!kind_value_check (path1
, 0, gfc_default_character_kind
))
3573 if (!type_check (path2
, 1, BT_CHARACTER
))
3575 if (!kind_value_check (path2
, 1, gfc_default_character_kind
))
3581 if (!type_check (status
, 2, BT_INTEGER
))
3584 if (!scalar_check (status
, 2))
3592 gfc_check_logical (gfc_expr
*a
, gfc_expr
*kind
)
3594 if (!type_check (a
, 0, BT_LOGICAL
))
3596 if (!kind_check (kind
, 1, BT_LOGICAL
))
3603 /* Min/max family. */
3606 min_max_args (gfc_actual_arglist
*args
)
3608 gfc_actual_arglist
*arg
;
3609 int i
, j
, nargs
, *nlabels
, nlabelless
;
3610 bool a1
= false, a2
= false;
3612 if (args
== NULL
|| args
->next
== NULL
)
3614 gfc_error ("Intrinsic %qs at %L must have at least two arguments",
3615 gfc_current_intrinsic
, gfc_current_intrinsic_where
);
3622 if (!args
->next
->name
)
3626 for (arg
= args
; arg
; arg
= arg
->next
)
3633 /* Note: Having a keywordless argument after an "arg=" is checked before. */
3635 nlabels
= XALLOCAVEC (int, nargs
);
3636 for (arg
= args
, i
= 0; arg
; arg
= arg
->next
, i
++)
3642 if (arg
->name
[0] != 'a' || arg
->name
[1] < '1' || arg
->name
[1] > '9')
3644 n
= strtol (&arg
->name
[1], &endp
, 10);
3645 if (endp
[0] != '\0')
3649 if (n
<= nlabelless
)
3662 gfc_error ("Missing %qs argument to the %s intrinsic at %L",
3663 !a1
? "a1" : "a2", gfc_current_intrinsic
,
3664 gfc_current_intrinsic_where
);
3668 /* Check for duplicates. */
3669 for (i
= 0; i
< nargs
; i
++)
3670 for (j
= i
+ 1; j
< nargs
; j
++)
3671 if (nlabels
[i
] == nlabels
[j
])
3677 gfc_error ("Duplicate argument %qs at %L to intrinsic %s", arg
->name
,
3678 &arg
->expr
->where
, gfc_current_intrinsic
);
3682 gfc_error ("Unknown argument %qs at %L to intrinsic %s", arg
->name
,
3683 &arg
->expr
->where
, gfc_current_intrinsic
);
3689 check_rest (bt type
, int kind
, gfc_actual_arglist
*arglist
)
3691 gfc_actual_arglist
*arg
, *tmp
;
3695 if (!min_max_args (arglist
))
3698 for (arg
= arglist
, n
=1; arg
; arg
= arg
->next
, n
++)
3701 if (x
->ts
.type
!= type
|| x
->ts
.kind
!= kind
)
3703 if (x
->ts
.type
== type
)
3705 if (x
->ts
.type
== BT_CHARACTER
)
3707 gfc_error ("Different character kinds at %L", &x
->where
);
3710 if (!gfc_notify_std (GFC_STD_GNU
, "Different type "
3711 "kinds at %L", &x
->where
))
3716 gfc_error ("%<a%d%> argument of %qs intrinsic at %L must be "
3717 "%s(%d)", n
, gfc_current_intrinsic
, &x
->where
,
3718 gfc_basic_typename (type
), kind
);
3723 for (tmp
= arglist
, m
=1; tmp
!= arg
; tmp
= tmp
->next
, m
++)
3724 if (!gfc_check_conformance (tmp
->expr
, x
,
3725 _("arguments 'a%d' and 'a%d' for "
3726 "intrinsic '%s'"), m
, n
,
3727 gfc_current_intrinsic
))
3736 gfc_check_min_max (gfc_actual_arglist
*arg
)
3740 if (!min_max_args (arg
))
3745 if (x
->ts
.type
== BT_CHARACTER
)
3747 if (!gfc_notify_std (GFC_STD_F2003
, "%qs intrinsic "
3748 "with CHARACTER argument at %L",
3749 gfc_current_intrinsic
, &x
->where
))
3752 else if (x
->ts
.type
!= BT_INTEGER
&& x
->ts
.type
!= BT_REAL
)
3754 gfc_error ("%<a1%> argument of %qs intrinsic at %L must be INTEGER, "
3755 "REAL or CHARACTER", gfc_current_intrinsic
, &x
->where
);
3759 return check_rest (x
->ts
.type
, x
->ts
.kind
, arg
);
3764 gfc_check_min_max_integer (gfc_actual_arglist
*arg
)
3766 return check_rest (BT_INTEGER
, gfc_default_integer_kind
, arg
);
3771 gfc_check_min_max_real (gfc_actual_arglist
*arg
)
3773 return check_rest (BT_REAL
, gfc_default_real_kind
, arg
);
3778 gfc_check_min_max_double (gfc_actual_arglist
*arg
)
3780 return check_rest (BT_REAL
, gfc_default_double_kind
, arg
);
3784 /* End of min/max family. */
3787 gfc_check_malloc (gfc_expr
*size
)
3789 if (!type_check (size
, 0, BT_INTEGER
))
3792 if (!scalar_check (size
, 0))
3800 gfc_check_matmul (gfc_expr
*matrix_a
, gfc_expr
*matrix_b
)
3802 if ((matrix_a
->ts
.type
!= BT_LOGICAL
) && !gfc_numeric_ts (&matrix_a
->ts
))
3804 gfc_error ("%qs argument of %qs intrinsic at %L must be numeric "
3805 "or LOGICAL", gfc_current_intrinsic_arg
[0]->name
,
3806 gfc_current_intrinsic
, &matrix_a
->where
);
3810 if ((matrix_b
->ts
.type
!= BT_LOGICAL
) && !gfc_numeric_ts (&matrix_b
->ts
))
3812 gfc_error ("%qs argument of %qs intrinsic at %L must be numeric "
3813 "or LOGICAL", gfc_current_intrinsic_arg
[1]->name
,
3814 gfc_current_intrinsic
, &matrix_b
->where
);
3818 if ((matrix_a
->ts
.type
== BT_LOGICAL
&& gfc_numeric_ts (&matrix_b
->ts
))
3819 || (gfc_numeric_ts (&matrix_a
->ts
) && matrix_b
->ts
.type
== BT_LOGICAL
))
3821 gfc_error ("Argument types of %qs intrinsic at %L must match (%s/%s)",
3822 gfc_current_intrinsic
, &matrix_a
->where
,
3823 gfc_typename(&matrix_a
->ts
), gfc_typename(&matrix_b
->ts
));
3827 switch (matrix_a
->rank
)
3830 if (!rank_check (matrix_b
, 1, 2))
3832 /* Check for case matrix_a has shape(m), matrix_b has shape (m, k). */
3833 if (!identical_dimen_shape (matrix_a
, 0, matrix_b
, 0))
3835 gfc_error ("Different shape on dimension 1 for arguments %qs "
3836 "and %qs at %L for intrinsic matmul",
3837 gfc_current_intrinsic_arg
[0]->name
,
3838 gfc_current_intrinsic_arg
[1]->name
, &matrix_a
->where
);
3844 if (matrix_b
->rank
!= 2)
3846 if (!rank_check (matrix_b
, 1, 1))
3849 /* matrix_b has rank 1 or 2 here. Common check for the cases
3850 - matrix_a has shape (n,m) and matrix_b has shape (m, k)
3851 - matrix_a has shape (n,m) and matrix_b has shape (m). */
3852 if (!identical_dimen_shape (matrix_a
, 1, matrix_b
, 0))
3854 gfc_error ("Different shape on dimension 2 for argument %qs and "
3855 "dimension 1 for argument %qs at %L for intrinsic "
3856 "matmul", gfc_current_intrinsic_arg
[0]->name
,
3857 gfc_current_intrinsic_arg
[1]->name
, &matrix_a
->where
);
3863 gfc_error ("%qs argument of %qs intrinsic at %L must be of rank "
3864 "1 or 2", gfc_current_intrinsic_arg
[0]->name
,
3865 gfc_current_intrinsic
, &matrix_a
->where
);
3873 /* Whoever came up with this interface was probably on something.
3874 The possibilities for the occupation of the second and third
3881 NULL MASK minloc(array, mask=m)
3884 I.e. in the case of minloc(array,mask), mask will be in the second
3885 position of the argument list and we'll have to fix that up. Also,
3886 add the BACK argument if that isn't present. */
3889 gfc_check_minloc_maxloc (gfc_actual_arglist
*ap
)
3891 gfc_expr
*a
, *m
, *d
, *k
, *b
;
3894 if (!int_or_real_or_char_check_f2003 (a
, 0) || !array_check (a
, 0))
3898 m
= ap
->next
->next
->expr
;
3899 k
= ap
->next
->next
->next
->expr
;
3900 b
= ap
->next
->next
->next
->next
->expr
;
3904 if (!type_check (b
, 4, BT_LOGICAL
) || !scalar_check (b
,4))
3909 b
= gfc_get_logical_expr (gfc_logical_4_kind
, NULL
, 0);
3910 ap
->next
->next
->next
->next
->expr
= b
;
3913 if (m
== NULL
&& d
!= NULL
&& d
->ts
.type
== BT_LOGICAL
3914 && ap
->next
->name
== NULL
)
3918 ap
->next
->expr
= NULL
;
3919 ap
->next
->next
->expr
= m
;
3922 if (!dim_check (d
, 1, false))
3925 if (!dim_rank_check (d
, a
, 0))
3928 if (m
!= NULL
&& !type_check (m
, 2, BT_LOGICAL
))
3932 && !gfc_check_conformance (a
, m
,
3933 _("arguments '%s' and '%s' for intrinsic %s"),
3934 gfc_current_intrinsic_arg
[0]->name
,
3935 gfc_current_intrinsic_arg
[2]->name
,
3936 gfc_current_intrinsic
))
3939 if (!kind_check (k
, 1, BT_INTEGER
))
3945 /* Check function for findloc. Mostly like gfc_check_minloc_maxloc
3946 above, with the additional "value" argument. */
3949 gfc_check_findloc (gfc_actual_arglist
*ap
)
3951 gfc_expr
*a
, *v
, *m
, *d
, *k
, *b
;
3955 if (!intrinsic_type_check (a
, 0) || !array_check (a
, 0))
3959 if (!intrinsic_type_check (v
, 1) || !scalar_check (v
,1))
3962 /* Check if the type are both logical. */
3963 a1
= a
->ts
.type
== BT_LOGICAL
;
3964 v1
= v
->ts
.type
== BT_LOGICAL
;
3965 if ((a1
&& !v1
) || (!a1
&& v1
))
3968 /* Check if the type are both character. */
3969 a1
= a
->ts
.type
== BT_CHARACTER
;
3970 v1
= v
->ts
.type
== BT_CHARACTER
;
3971 if ((a1
&& !v1
) || (!a1
&& v1
))
3974 /* Check the kind of the characters argument match. */
3975 if (a1
&& v1
&& a
->ts
.kind
!= v
->ts
.kind
)
3978 d
= ap
->next
->next
->expr
;
3979 m
= ap
->next
->next
->next
->expr
;
3980 k
= ap
->next
->next
->next
->next
->expr
;
3981 b
= ap
->next
->next
->next
->next
->next
->expr
;
3985 if (!type_check (b
, 5, BT_LOGICAL
) || !scalar_check (b
,4))
3990 b
= gfc_get_logical_expr (gfc_logical_4_kind
, NULL
, 0);
3991 ap
->next
->next
->next
->next
->next
->expr
= b
;
3994 if (m
== NULL
&& d
!= NULL
&& d
->ts
.type
== BT_LOGICAL
3995 && ap
->next
->name
== NULL
)
3999 ap
->next
->next
->expr
= NULL
;
4000 ap
->next
->next
->next
->expr
= m
;
4003 if (!dim_check (d
, 2, false))
4006 if (!dim_rank_check (d
, a
, 0))
4009 if (m
!= NULL
&& !type_check (m
, 3, BT_LOGICAL
))
4013 && !gfc_check_conformance (a
, m
,
4014 _("arguments '%s' and '%s' for intrinsic %s"),
4015 gfc_current_intrinsic_arg
[0]->name
,
4016 gfc_current_intrinsic_arg
[3]->name
,
4017 gfc_current_intrinsic
))
4020 if (!kind_check (k
, 1, BT_INTEGER
))
4026 gfc_error ("Argument %qs of %qs intrinsic at %L must be in type "
4027 "conformance to argument %qs at %L",
4028 gfc_current_intrinsic_arg
[0]->name
,
4029 gfc_current_intrinsic
, &a
->where
,
4030 gfc_current_intrinsic_arg
[1]->name
, &v
->where
);
4035 /* Similar to minloc/maxloc, the argument list might need to be
4036 reordered for the MINVAL, MAXVAL, PRODUCT, and SUM intrinsics. The
4037 difference is that MINLOC/MAXLOC take an additional KIND argument.
4038 The possibilities are:
4044 NULL MASK minval(array, mask=m)
4047 I.e. in the case of minval(array,mask), mask will be in the second
4048 position of the argument list and we'll have to fix that up. */
4051 check_reduction (gfc_actual_arglist
*ap
)
4053 gfc_expr
*a
, *m
, *d
;
4057 m
= ap
->next
->next
->expr
;
4059 if (m
== NULL
&& d
!= NULL
&& d
->ts
.type
== BT_LOGICAL
4060 && ap
->next
->name
== NULL
)
4064 ap
->next
->expr
= NULL
;
4065 ap
->next
->next
->expr
= m
;
4068 if (!dim_check (d
, 1, false))
4071 if (!dim_rank_check (d
, a
, 0))
4074 if (m
!= NULL
&& !type_check (m
, 2, BT_LOGICAL
))
4078 && !gfc_check_conformance (a
, m
,
4079 _("arguments '%s' and '%s' for intrinsic %s"),
4080 gfc_current_intrinsic_arg
[0]->name
,
4081 gfc_current_intrinsic_arg
[2]->name
,
4082 gfc_current_intrinsic
))
4090 gfc_check_minval_maxval (gfc_actual_arglist
*ap
)
4092 if (!int_or_real_or_char_check_f2003 (ap
->expr
, 0)
4093 || !array_check (ap
->expr
, 0))
4096 return check_reduction (ap
);
4101 gfc_check_product_sum (gfc_actual_arglist
*ap
)
4103 if (!numeric_check (ap
->expr
, 0)
4104 || !array_check (ap
->expr
, 0))
4107 return check_reduction (ap
);
4111 /* For IANY, IALL and IPARITY. */
4114 gfc_check_mask (gfc_expr
*i
, gfc_expr
*kind
)
4118 if (!type_check (i
, 0, BT_INTEGER
))
4121 if (!nonnegative_check ("I", i
))
4124 if (!kind_check (kind
, 1, BT_INTEGER
))
4128 gfc_extract_int (kind
, &k
);
4130 k
= gfc_default_integer_kind
;
4132 if (!less_than_bitsizekind ("I", i
, k
))
4140 gfc_check_transf_bit_intrins (gfc_actual_arglist
*ap
)
4142 if (ap
->expr
->ts
.type
!= BT_INTEGER
)
4144 gfc_error ("%qs argument of %qs intrinsic at %L must be INTEGER",
4145 gfc_current_intrinsic_arg
[0]->name
,
4146 gfc_current_intrinsic
, &ap
->expr
->where
);
4150 if (!array_check (ap
->expr
, 0))
4153 return check_reduction (ap
);
4158 gfc_check_merge (gfc_expr
*tsource
, gfc_expr
*fsource
, gfc_expr
*mask
)
4160 if (gfc_invalid_null_arg (tsource
))
4163 if (gfc_invalid_null_arg (fsource
))
4166 if (!same_type_check (tsource
, 0, fsource
, 1))
4169 if (!type_check (mask
, 2, BT_LOGICAL
))
4172 if (tsource
->ts
.type
== BT_CHARACTER
)
4173 return gfc_check_same_strlen (tsource
, fsource
, "MERGE intrinsic");
4180 gfc_check_merge_bits (gfc_expr
*i
, gfc_expr
*j
, gfc_expr
*mask
)
4182 /* i and j cannot both be BOZ literal constants. */
4183 if (!boz_args_check (i
, j
))
4186 /* If i is BOZ and j is integer, convert i to type of j. */
4187 if (i
->ts
.type
== BT_BOZ
&& j
->ts
.type
== BT_INTEGER
4188 && !gfc_boz2int (i
, j
->ts
.kind
))
4191 /* If j is BOZ and i is integer, convert j to type of i. */
4192 if (j
->ts
.type
== BT_BOZ
&& i
->ts
.type
== BT_INTEGER
4193 && !gfc_boz2int (j
, i
->ts
.kind
))
4196 if (!type_check (i
, 0, BT_INTEGER
))
4199 if (!type_check (j
, 1, BT_INTEGER
))
4202 if (!same_type_check (i
, 0, j
, 1))
4205 if (mask
->ts
.type
== BT_BOZ
&& !gfc_boz2int(mask
, i
->ts
.kind
))
4208 if (!type_check (mask
, 2, BT_INTEGER
))
4211 if (!same_type_check (i
, 0, mask
, 2))
4219 gfc_check_move_alloc (gfc_expr
*from
, gfc_expr
*to
)
4221 if (!variable_check (from
, 0, false))
4223 if (!allocatable_check (from
, 0))
4225 if (gfc_is_coindexed (from
))
4227 gfc_error ("The FROM argument to MOVE_ALLOC at %L shall not be "
4228 "coindexed", &from
->where
);
4232 if (!variable_check (to
, 1, false))
4234 if (!allocatable_check (to
, 1))
4236 if (gfc_is_coindexed (to
))
4238 gfc_error ("The TO argument to MOVE_ALLOC at %L shall not be "
4239 "coindexed", &to
->where
);
4243 if (from
->ts
.type
== BT_CLASS
&& to
->ts
.type
== BT_DERIVED
)
4245 gfc_error ("The TO arguments in MOVE_ALLOC at %L must be "
4246 "polymorphic if FROM is polymorphic",
4251 if (!same_type_check (to
, 1, from
, 0))
4254 if (to
->rank
!= from
->rank
)
4256 gfc_error ("The FROM and TO arguments of the MOVE_ALLOC intrinsic at %L "
4257 "must have the same rank %d/%d", &to
->where
, from
->rank
,
4262 /* IR F08/0040; cf. 12-006A. */
4263 if (gfc_get_corank (to
) != gfc_get_corank (from
))
4265 gfc_error ("The FROM and TO arguments of the MOVE_ALLOC intrinsic at %L "
4266 "must have the same corank %d/%d", &to
->where
,
4267 gfc_get_corank (from
), gfc_get_corank (to
));
4271 /* This is based losely on F2003 12.4.1.7. It is intended to prevent
4272 the likes of to = sym->cmp1->cmp2 and from = sym->cmp1, where cmp1
4273 and cmp2 are allocatable. After the allocation is transferred,
4274 the 'to' chain is broken by the nullification of the 'from'. A bit
4275 of reflection reveals that this can only occur for derived types
4276 with recursive allocatable components. */
4277 if (to
->expr_type
== EXPR_VARIABLE
&& from
->expr_type
== EXPR_VARIABLE
4278 && !strcmp (to
->symtree
->n
.sym
->name
, from
->symtree
->n
.sym
->name
))
4280 gfc_ref
*to_ref
, *from_ref
;
4282 from_ref
= from
->ref
;
4283 bool aliasing
= true;
4285 for (; from_ref
&& to_ref
;
4286 from_ref
= from_ref
->next
, to_ref
= to_ref
->next
)
4288 if (to_ref
->type
!= from
->ref
->type
)
4290 else if (to_ref
->type
== REF_ARRAY
4291 && to_ref
->u
.ar
.type
!= AR_FULL
4292 && from_ref
->u
.ar
.type
!= AR_FULL
)
4293 /* Play safe; assume sections and elements are different. */
4295 else if (to_ref
->type
== REF_COMPONENT
4296 && to_ref
->u
.c
.component
!= from_ref
->u
.c
.component
)
4305 gfc_error ("The FROM and TO arguments at %L violate aliasing "
4306 "restrictions (F2003 12.4.1.7)", &to
->where
);
4311 /* CLASS arguments: Make sure the vtab of from is present. */
4312 if (to
->ts
.type
== BT_CLASS
&& !UNLIMITED_POLY (from
))
4313 gfc_find_vtab (&from
->ts
);
4320 gfc_check_nearest (gfc_expr
*x
, gfc_expr
*s
)
4322 if (!type_check (x
, 0, BT_REAL
))
4325 if (!type_check (s
, 1, BT_REAL
))
4328 if (s
->expr_type
== EXPR_CONSTANT
)
4330 if (mpfr_sgn (s
->value
.real
) == 0)
4332 gfc_error ("Argument %<S%> of NEAREST at %L shall not be zero",
4343 gfc_check_new_line (gfc_expr
*a
)
4345 if (!type_check (a
, 0, BT_CHARACTER
))
4353 gfc_check_norm2 (gfc_expr
*array
, gfc_expr
*dim
)
4355 if (!type_check (array
, 0, BT_REAL
))
4358 if (!array_check (array
, 0))
4361 if (!dim_rank_check (dim
, array
, false))
4368 gfc_check_null (gfc_expr
*mold
)
4370 symbol_attribute attr
;
4375 if (!variable_check (mold
, 0, true))
4378 attr
= gfc_variable_attr (mold
, NULL
);
4380 if (!attr
.pointer
&& !attr
.proc_pointer
&& !attr
.allocatable
)
4382 gfc_error ("%qs argument of %qs intrinsic at %L must be a POINTER, "
4383 "ALLOCATABLE or procedure pointer",
4384 gfc_current_intrinsic_arg
[0]->name
,
4385 gfc_current_intrinsic
, &mold
->where
);
4389 if (attr
.allocatable
4390 && !gfc_notify_std (GFC_STD_F2003
, "NULL intrinsic with "
4391 "allocatable MOLD at %L", &mold
->where
))
4395 if (gfc_is_coindexed (mold
))
4397 gfc_error ("%qs argument of %qs intrinsic at %L shall not be "
4398 "coindexed", gfc_current_intrinsic_arg
[0]->name
,
4399 gfc_current_intrinsic
, &mold
->where
);
4408 gfc_check_pack (gfc_expr
*array
, gfc_expr
*mask
, gfc_expr
*vector
)
4410 if (!array_check (array
, 0))
4413 if (!type_check (mask
, 1, BT_LOGICAL
))
4416 if (!gfc_check_conformance (array
, mask
,
4417 _("arguments '%s' and '%s' for intrinsic '%s'"),
4418 gfc_current_intrinsic_arg
[0]->name
,
4419 gfc_current_intrinsic_arg
[1]->name
,
4420 gfc_current_intrinsic
))
4425 mpz_t array_size
, vector_size
;
4426 bool have_array_size
, have_vector_size
;
4428 if (!same_type_check (array
, 0, vector
, 2))
4431 if (!rank_check (vector
, 2, 1))
4434 /* VECTOR requires at least as many elements as MASK
4435 has .TRUE. values. */
4436 have_array_size
= gfc_array_size(array
, &array_size
);
4437 have_vector_size
= gfc_array_size(vector
, &vector_size
);
4439 if (have_vector_size
4440 && (mask
->expr_type
== EXPR_ARRAY
4441 || (mask
->expr_type
== EXPR_CONSTANT
4442 && have_array_size
)))
4444 int mask_true_values
= 0;
4446 if (mask
->expr_type
== EXPR_ARRAY
)
4448 gfc_constructor
*mask_ctor
;
4449 mask_ctor
= gfc_constructor_first (mask
->value
.constructor
);
4452 if (mask_ctor
->expr
->expr_type
!= EXPR_CONSTANT
)
4454 mask_true_values
= 0;
4458 if (mask_ctor
->expr
->value
.logical
)
4461 mask_ctor
= gfc_constructor_next (mask_ctor
);
4464 else if (mask
->expr_type
== EXPR_CONSTANT
&& mask
->value
.logical
)
4465 mask_true_values
= mpz_get_si (array_size
);
4467 if (mpz_get_si (vector_size
) < mask_true_values
)
4469 gfc_error ("%qs argument of %qs intrinsic at %L must "
4470 "provide at least as many elements as there "
4471 "are .TRUE. values in %qs (%ld/%d)",
4472 gfc_current_intrinsic_arg
[2]->name
,
4473 gfc_current_intrinsic
, &vector
->where
,
4474 gfc_current_intrinsic_arg
[1]->name
,
4475 mpz_get_si (vector_size
), mask_true_values
);
4480 if (have_array_size
)
4481 mpz_clear (array_size
);
4482 if (have_vector_size
)
4483 mpz_clear (vector_size
);
4491 gfc_check_parity (gfc_expr
*mask
, gfc_expr
*dim
)
4493 if (!type_check (mask
, 0, BT_LOGICAL
))
4496 if (!array_check (mask
, 0))
4499 if (!dim_rank_check (dim
, mask
, false))
4507 gfc_check_precision (gfc_expr
*x
)
4509 if (!real_or_complex_check (x
, 0))
4517 gfc_check_present (gfc_expr
*a
)
4521 if (!variable_check (a
, 0, true))
4524 sym
= a
->symtree
->n
.sym
;
4525 if (!sym
->attr
.dummy
)
4527 gfc_error ("%qs argument of %qs intrinsic at %L must be of a "
4528 "dummy variable", gfc_current_intrinsic_arg
[0]->name
,
4529 gfc_current_intrinsic
, &a
->where
);
4533 /* For CLASS, the optional attribute might be set at either location. */
4534 if ((sym
->ts
.type
!= BT_CLASS
|| !CLASS_DATA (sym
)->attr
.optional
)
4535 && !sym
->attr
.optional
)
4537 gfc_error ("%qs argument of %qs intrinsic at %L must be of "
4538 "an OPTIONAL dummy variable",
4539 gfc_current_intrinsic_arg
[0]->name
, gfc_current_intrinsic
,
4544 /* 13.14.82 PRESENT(A)
4546 Argument. A shall be the name of an optional dummy argument that is
4547 accessible in the subprogram in which the PRESENT function reference
4551 && !(a
->ref
->next
== NULL
&& a
->ref
->type
== REF_ARRAY
4552 && (a
->ref
->u
.ar
.type
== AR_FULL
4553 || (a
->ref
->u
.ar
.type
== AR_ELEMENT
4554 && a
->ref
->u
.ar
.as
->rank
== 0))))
4556 gfc_error ("%qs argument of %qs intrinsic at %L must not be a "
4557 "subobject of %qs", gfc_current_intrinsic_arg
[0]->name
,
4558 gfc_current_intrinsic
, &a
->where
, sym
->name
);
4567 gfc_check_radix (gfc_expr
*x
)
4569 if (!int_or_real_check (x
, 0))
4577 gfc_check_range (gfc_expr
*x
)
4579 if (!numeric_check (x
, 0))
4587 gfc_check_rank (gfc_expr
*a
)
4589 /* Any data object is allowed; a "data object" is a "constant (4.1.3),
4590 variable (6), or subobject of a constant (2.4.3.2.3)" (F2008, 1.3.45). */
4592 bool is_variable
= true;
4594 /* Functions returning pointers are regarded as variable, cf. F2008, R602. */
4595 if (a
->expr_type
== EXPR_FUNCTION
)
4596 is_variable
= a
->value
.function
.esym
4597 ? a
->value
.function
.esym
->result
->attr
.pointer
4598 : a
->symtree
->n
.sym
->result
->attr
.pointer
;
4600 if (a
->expr_type
== EXPR_OP
4601 || a
->expr_type
== EXPR_NULL
4602 || a
->expr_type
== EXPR_COMPCALL
4603 || a
->expr_type
== EXPR_PPC
4604 || a
->ts
.type
== BT_PROCEDURE
4607 gfc_error ("The argument of the RANK intrinsic at %L must be a data "
4608 "object", &a
->where
);
4617 gfc_check_real (gfc_expr
*a
, gfc_expr
*kind
)
4619 if (!kind_check (kind
, 1, BT_REAL
))
4622 /* BOZ is dealt with in gfc_simplify_real. */
4623 if (a
->ts
.type
== BT_BOZ
)
4626 if (!numeric_check (a
, 0))
4634 gfc_check_rename (gfc_expr
*path1
, gfc_expr
*path2
)
4636 if (!type_check (path1
, 0, BT_CHARACTER
))
4638 if (!kind_value_check (path1
, 0, gfc_default_character_kind
))
4641 if (!type_check (path2
, 1, BT_CHARACTER
))
4643 if (!kind_value_check (path2
, 1, gfc_default_character_kind
))
4651 gfc_check_rename_sub (gfc_expr
*path1
, gfc_expr
*path2
, gfc_expr
*status
)
4653 if (!type_check (path1
, 0, BT_CHARACTER
))
4655 if (!kind_value_check (path1
, 0, gfc_default_character_kind
))
4658 if (!type_check (path2
, 1, BT_CHARACTER
))
4660 if (!kind_value_check (path2
, 1, gfc_default_character_kind
))
4666 if (!type_check (status
, 2, BT_INTEGER
))
4669 if (!scalar_check (status
, 2))
4677 gfc_check_repeat (gfc_expr
*x
, gfc_expr
*y
)
4679 if (!type_check (x
, 0, BT_CHARACTER
))
4682 if (!scalar_check (x
, 0))
4685 if (!type_check (y
, 0, BT_INTEGER
))
4688 if (!scalar_check (y
, 1))
4696 gfc_check_reshape (gfc_expr
*source
, gfc_expr
*shape
,
4697 gfc_expr
*pad
, gfc_expr
*order
)
4702 bool shape_is_const
;
4704 if (!array_check (source
, 0))
4707 if (!rank_check (shape
, 1, 1))
4710 if (!type_check (shape
, 1, BT_INTEGER
))
4713 if (!gfc_array_size (shape
, &size
))
4715 gfc_error ("%<shape%> argument of %<reshape%> intrinsic at %L must be an "
4716 "array of constant size", &shape
->where
);
4720 shape_size
= mpz_get_ui (size
);
4723 if (shape_size
<= 0)
4725 gfc_error ("%qs argument of %qs intrinsic at %L is empty",
4726 gfc_current_intrinsic_arg
[1]->name
, gfc_current_intrinsic
,
4730 else if (shape_size
> GFC_MAX_DIMENSIONS
)
4732 gfc_error ("%<shape%> argument of %<reshape%> intrinsic at %L has more "
4733 "than %d elements", &shape
->where
, GFC_MAX_DIMENSIONS
);
4737 gfc_simplify_expr (shape
, 0);
4738 shape_is_const
= gfc_is_constant_expr (shape
);
4740 if (shape
->expr_type
== EXPR_ARRAY
&& shape_is_const
)
4744 for (i
= 0; i
< shape_size
; ++i
)
4746 e
= gfc_constructor_lookup_expr (shape
->value
.constructor
, i
);
4747 if (e
->expr_type
!= EXPR_CONSTANT
)
4750 gfc_extract_int (e
, &extent
);
4753 gfc_error ("%qs argument of %qs intrinsic at %L has "
4754 "negative element (%d)",
4755 gfc_current_intrinsic_arg
[1]->name
,
4756 gfc_current_intrinsic
, &shape
->where
, extent
);
4764 if (!same_type_check (source
, 0, pad
, 2))
4767 if (!array_check (pad
, 2))
4773 if (!array_check (order
, 3))
4776 if (!type_check (order
, 3, BT_INTEGER
))
4779 if (order
->expr_type
== EXPR_ARRAY
&& gfc_is_constant_expr (order
))
4781 int i
, order_size
, dim
, perm
[GFC_MAX_DIMENSIONS
];
4784 for (i
= 0; i
< GFC_MAX_DIMENSIONS
; ++i
)
4787 gfc_array_size (order
, &size
);
4788 order_size
= mpz_get_ui (size
);
4791 if (order_size
!= shape_size
)
4793 gfc_error ("%qs argument of %qs intrinsic at %L "
4794 "has wrong number of elements (%d/%d)",
4795 gfc_current_intrinsic_arg
[3]->name
,
4796 gfc_current_intrinsic
, &order
->where
,
4797 order_size
, shape_size
);
4801 for (i
= 1; i
<= order_size
; ++i
)
4803 e
= gfc_constructor_lookup_expr (order
->value
.constructor
, i
-1);
4804 if (e
->expr_type
!= EXPR_CONSTANT
)
4807 gfc_extract_int (e
, &dim
);
4809 if (dim
< 1 || dim
> order_size
)
4811 gfc_error ("%qs argument of %qs intrinsic at %L "
4812 "has out-of-range dimension (%d)",
4813 gfc_current_intrinsic_arg
[3]->name
,
4814 gfc_current_intrinsic
, &e
->where
, dim
);
4818 if (perm
[dim
-1] != 0)
4820 gfc_error ("%qs argument of %qs intrinsic at %L has "
4821 "invalid permutation of dimensions (dimension "
4823 gfc_current_intrinsic_arg
[3]->name
,
4824 gfc_current_intrinsic
, &e
->where
, dim
);
4833 if (pad
== NULL
&& shape
->expr_type
== EXPR_ARRAY
&& shape_is_const
4834 && !(source
->expr_type
== EXPR_VARIABLE
&& source
->symtree
->n
.sym
->as
4835 && source
->symtree
->n
.sym
->as
->type
== AS_ASSUMED_SIZE
))
4837 /* Check the match in size between source and destination. */
4838 if (gfc_array_size (source
, &nelems
))
4844 mpz_init_set_ui (size
, 1);
4845 for (c
= gfc_constructor_first (shape
->value
.constructor
);
4846 c
; c
= gfc_constructor_next (c
))
4847 mpz_mul (size
, size
, c
->expr
->value
.integer
);
4849 test
= mpz_cmp (nelems
, size
) < 0 && mpz_cmp_ui (size
, 0) > 0;
4855 gfc_error ("Without padding, there are not enough elements "
4856 "in the intrinsic RESHAPE source at %L to match "
4857 "the shape", &source
->where
);
4868 gfc_check_same_type_as (gfc_expr
*a
, gfc_expr
*b
)
4870 if (a
->ts
.type
!= BT_DERIVED
&& a
->ts
.type
!= BT_CLASS
)
4872 gfc_error ("%qs argument of %qs intrinsic at %L "
4873 "cannot be of type %s",
4874 gfc_current_intrinsic_arg
[0]->name
,
4875 gfc_current_intrinsic
,
4876 &a
->where
, gfc_typename (a
));
4880 if (!(gfc_type_is_extensible (a
->ts
.u
.derived
) || UNLIMITED_POLY (a
)))
4882 gfc_error ("%qs argument of %qs intrinsic at %L "
4883 "must be of an extensible type",
4884 gfc_current_intrinsic_arg
[0]->name
, gfc_current_intrinsic
,
4889 if (b
->ts
.type
!= BT_DERIVED
&& b
->ts
.type
!= BT_CLASS
)
4891 gfc_error ("%qs argument of %qs intrinsic at %L "
4892 "cannot be of type %s",
4893 gfc_current_intrinsic_arg
[0]->name
,
4894 gfc_current_intrinsic
,
4895 &b
->where
, gfc_typename (b
));
4899 if (!(gfc_type_is_extensible (b
->ts
.u
.derived
) || UNLIMITED_POLY (b
)))
4901 gfc_error ("%qs argument of %qs intrinsic at %L "
4902 "must be of an extensible type",
4903 gfc_current_intrinsic_arg
[1]->name
, gfc_current_intrinsic
,
4913 gfc_check_scale (gfc_expr
*x
, gfc_expr
*i
)
4915 if (!type_check (x
, 0, BT_REAL
))
4918 if (!type_check (i
, 1, BT_INTEGER
))
4926 gfc_check_scan (gfc_expr
*x
, gfc_expr
*y
, gfc_expr
*z
, gfc_expr
*kind
)
4928 if (!type_check (x
, 0, BT_CHARACTER
))
4931 if (!type_check (y
, 1, BT_CHARACTER
))
4934 if (z
!= NULL
&& !type_check (z
, 2, BT_LOGICAL
))
4937 if (!kind_check (kind
, 3, BT_INTEGER
))
4939 if (kind
&& !gfc_notify_std (GFC_STD_F2003
, "%qs intrinsic "
4940 "with KIND argument at %L",
4941 gfc_current_intrinsic
, &kind
->where
))
4944 if (!same_type_check (x
, 0, y
, 1))
4952 gfc_check_secnds (gfc_expr
*r
)
4954 if (!type_check (r
, 0, BT_REAL
))
4957 if (!kind_value_check (r
, 0, 4))
4960 if (!scalar_check (r
, 0))
4968 gfc_check_selected_char_kind (gfc_expr
*name
)
4970 if (!type_check (name
, 0, BT_CHARACTER
))
4973 if (!kind_value_check (name
, 0, gfc_default_character_kind
))
4976 if (!scalar_check (name
, 0))
4984 gfc_check_selected_int_kind (gfc_expr
*r
)
4986 if (!type_check (r
, 0, BT_INTEGER
))
4989 if (!scalar_check (r
, 0))
4997 gfc_check_selected_real_kind (gfc_expr
*p
, gfc_expr
*r
, gfc_expr
*radix
)
4999 if (p
== NULL
&& r
== NULL
5000 && !gfc_notify_std (GFC_STD_F2008
, "SELECTED_REAL_KIND with"
5001 " neither %<P%> nor %<R%> argument at %L",
5002 gfc_current_intrinsic_where
))
5007 if (!type_check (p
, 0, BT_INTEGER
))
5010 if (!scalar_check (p
, 0))
5016 if (!type_check (r
, 1, BT_INTEGER
))
5019 if (!scalar_check (r
, 1))
5025 if (!type_check (radix
, 1, BT_INTEGER
))
5028 if (!scalar_check (radix
, 1))
5031 if (!gfc_notify_std (GFC_STD_F2008
, "%qs intrinsic with "
5032 "RADIX argument at %L", gfc_current_intrinsic
,
5042 gfc_check_set_exponent (gfc_expr
*x
, gfc_expr
*i
)
5044 if (!type_check (x
, 0, BT_REAL
))
5047 if (!type_check (i
, 1, BT_INTEGER
))
5055 gfc_check_shape (gfc_expr
*source
, gfc_expr
*kind
)
5059 if (gfc_invalid_null_arg (source
))
5062 if (!kind_check (kind
, 1, BT_INTEGER
))
5064 if (kind
&& !gfc_notify_std (GFC_STD_F2003
, "%qs intrinsic "
5065 "with KIND argument at %L",
5066 gfc_current_intrinsic
, &kind
->where
))
5069 if (source
->rank
== 0 || source
->expr_type
!= EXPR_VARIABLE
)
5072 if (source
->ref
== NULL
)
5075 ar
= gfc_find_array_ref (source
);
5077 if (ar
->as
&& ar
->as
->type
== AS_ASSUMED_SIZE
&& ar
->type
== AR_FULL
)
5079 gfc_error ("%<source%> argument of %<shape%> intrinsic at %L must not be "
5080 "an assumed size array", &source
->where
);
5089 gfc_check_shift (gfc_expr
*i
, gfc_expr
*shift
)
5091 if (!type_check (i
, 0, BT_INTEGER
))
5094 if (!type_check (shift
, 0, BT_INTEGER
))
5097 if (!nonnegative_check ("SHIFT", shift
))
5100 if (!less_than_bitsize1 ("I", i
, "SHIFT", shift
, true))
5108 gfc_check_sign (gfc_expr
*a
, gfc_expr
*b
)
5110 if (!int_or_real_check (a
, 0))
5113 if (!same_type_check (a
, 0, b
, 1))
5121 gfc_check_size (gfc_expr
*array
, gfc_expr
*dim
, gfc_expr
*kind
)
5123 if (!array_check (array
, 0))
5126 if (!dim_check (dim
, 1, true))
5129 if (!dim_rank_check (dim
, array
, 0))
5132 if (!kind_check (kind
, 2, BT_INTEGER
))
5134 if (kind
&& !gfc_notify_std (GFC_STD_F2003
, "%qs intrinsic "
5135 "with KIND argument at %L",
5136 gfc_current_intrinsic
, &kind
->where
))
5145 gfc_check_sizeof (gfc_expr
*arg
)
5147 if (gfc_invalid_null_arg (arg
))
5150 if (arg
->ts
.type
== BT_PROCEDURE
)
5152 gfc_error ("%qs argument of %qs intrinsic at %L shall not be a procedure",
5153 gfc_current_intrinsic_arg
[0]->name
, gfc_current_intrinsic
,
5158 /* TYPE(*) is acceptable if and only if it uses an array descriptor. */
5159 if (arg
->ts
.type
== BT_ASSUMED
5160 && (arg
->symtree
->n
.sym
->as
== NULL
5161 || (arg
->symtree
->n
.sym
->as
->type
!= AS_ASSUMED_SHAPE
5162 && arg
->symtree
->n
.sym
->as
->type
!= AS_DEFERRED
5163 && arg
->symtree
->n
.sym
->as
->type
!= AS_ASSUMED_RANK
)))
5165 gfc_error ("%qs argument of %qs intrinsic at %L shall not be TYPE(*)",
5166 gfc_current_intrinsic_arg
[0]->name
, gfc_current_intrinsic
,
5171 if (arg
->rank
&& arg
->expr_type
== EXPR_VARIABLE
5172 && arg
->symtree
->n
.sym
->as
!= NULL
5173 && arg
->symtree
->n
.sym
->as
->type
== AS_ASSUMED_SIZE
&& arg
->ref
5174 && arg
->ref
->type
== REF_ARRAY
&& arg
->ref
->u
.ar
.type
== AR_FULL
)
5176 gfc_error ("%qs argument of %qs intrinsic at %L shall not be an "
5177 "assumed-size array", gfc_current_intrinsic_arg
[0]->name
,
5178 gfc_current_intrinsic
, &arg
->where
);
5186 /* Check whether an expression is interoperable. When returning false,
5187 msg is set to a string telling why the expression is not interoperable,
5188 otherwise, it is set to NULL. The msg string can be used in diagnostics.
5189 If c_loc is true, character with len > 1 are allowed (cf. Fortran
5190 2003corr5); additionally, assumed-shape/assumed-rank/deferred-shape
5191 arrays are permitted. And if c_f_ptr is true, deferred-shape arrays
5195 is_c_interoperable (gfc_expr
*expr
, const char **msg
, bool c_loc
, bool c_f_ptr
)
5199 if (expr
->expr_type
== EXPR_NULL
)
5201 *msg
= "NULL() is not interoperable";
5205 if (expr
->ts
.type
== BT_CLASS
)
5207 *msg
= "Expression is polymorphic";
5211 if (expr
->ts
.type
== BT_DERIVED
&& !expr
->ts
.u
.derived
->attr
.is_bind_c
5212 && !expr
->ts
.u
.derived
->ts
.is_iso_c
)
5214 *msg
= "Expression is a noninteroperable derived type";
5218 if (expr
->ts
.type
== BT_PROCEDURE
)
5220 *msg
= "Procedure unexpected as argument";
5224 if (gfc_notification_std (GFC_STD_GNU
) && expr
->ts
.type
== BT_LOGICAL
)
5227 for (i
= 0; gfc_logical_kinds
[i
].kind
; i
++)
5228 if (gfc_logical_kinds
[i
].kind
== expr
->ts
.kind
)
5230 *msg
= "Extension to use a non-C_Bool-kind LOGICAL";
5234 if (gfc_notification_std (GFC_STD_GNU
) && expr
->ts
.type
== BT_CHARACTER
5235 && expr
->ts
.kind
!= 1)
5237 *msg
= "Extension to use a non-C_CHAR-kind CHARACTER";
5241 if (expr
->ts
.type
== BT_CHARACTER
) {
5242 if (expr
->ts
.deferred
)
5244 /* TS 29113 allows deferred-length strings as dummy arguments,
5245 but it is not an interoperable type. */
5246 *msg
= "Expression shall not be a deferred-length string";
5250 if (expr
->ts
.u
.cl
&& expr
->ts
.u
.cl
->length
5251 && !gfc_simplify_expr (expr
->ts
.u
.cl
->length
, 0))
5252 gfc_internal_error ("is_c_interoperable(): gfc_simplify_expr failed");
5254 if (!c_loc
&& expr
->ts
.u
.cl
5255 && (!expr
->ts
.u
.cl
->length
5256 || expr
->ts
.u
.cl
->length
->expr_type
!= EXPR_CONSTANT
5257 || mpz_cmp_si (expr
->ts
.u
.cl
->length
->value
.integer
, 1) != 0))
5259 *msg
= "Type shall have a character length of 1";
5264 /* Note: The following checks are about interoperatable variables, Fortran
5265 15.3.5/15.3.6. In intrinsics like C_LOC or in procedure interface, more
5266 is allowed, e.g. assumed-shape arrays with TS 29113. */
5268 if (gfc_is_coarray (expr
))
5270 *msg
= "Coarrays are not interoperable";
5274 if (!c_loc
&& expr
->rank
> 0 && expr
->expr_type
!= EXPR_ARRAY
)
5276 gfc_array_ref
*ar
= gfc_find_array_ref (expr
);
5277 if (ar
->type
!= AR_FULL
)
5279 *msg
= "Only whole-arrays are interoperable";
5282 if (!c_f_ptr
&& ar
->as
->type
!= AS_EXPLICIT
5283 && ar
->as
->type
!= AS_ASSUMED_SIZE
)
5285 *msg
= "Only explicit-size and assumed-size arrays are interoperable";
5295 gfc_check_c_sizeof (gfc_expr
*arg
)
5299 if (!is_c_interoperable (arg
, &msg
, false, false))
5301 gfc_error ("%qs argument of %qs intrinsic at %L must be an "
5302 "interoperable data entity: %s",
5303 gfc_current_intrinsic_arg
[0]->name
, gfc_current_intrinsic
,
5308 if (arg
->ts
.type
== BT_ASSUMED
)
5310 gfc_error ("%qs argument of %qs intrinsic at %L shall not be "
5312 gfc_current_intrinsic_arg
[0]->name
, gfc_current_intrinsic
,
5317 if (arg
->rank
&& arg
->expr_type
== EXPR_VARIABLE
5318 && arg
->symtree
->n
.sym
->as
!= NULL
5319 && arg
->symtree
->n
.sym
->as
->type
== AS_ASSUMED_SIZE
&& arg
->ref
5320 && arg
->ref
->type
== REF_ARRAY
&& arg
->ref
->u
.ar
.type
== AR_FULL
)
5322 gfc_error ("%qs argument of %qs intrinsic at %L shall not be an "
5323 "assumed-size array", gfc_current_intrinsic_arg
[0]->name
,
5324 gfc_current_intrinsic
, &arg
->where
);
5333 gfc_check_c_associated (gfc_expr
*c_ptr_1
, gfc_expr
*c_ptr_2
)
5335 if (c_ptr_1
->ts
.type
!= BT_DERIVED
5336 || c_ptr_1
->ts
.u
.derived
->from_intmod
!= INTMOD_ISO_C_BINDING
5337 || (c_ptr_1
->ts
.u
.derived
->intmod_sym_id
!= ISOCBINDING_PTR
5338 && c_ptr_1
->ts
.u
.derived
->intmod_sym_id
!= ISOCBINDING_FUNPTR
))
5340 gfc_error ("Argument C_PTR_1 at %L to C_ASSOCIATED shall have the "
5341 "type TYPE(C_PTR) or TYPE(C_FUNPTR)", &c_ptr_1
->where
);
5345 if (!scalar_check (c_ptr_1
, 0))
5349 && (c_ptr_2
->ts
.type
!= BT_DERIVED
5350 || c_ptr_2
->ts
.u
.derived
->from_intmod
!= INTMOD_ISO_C_BINDING
5351 || (c_ptr_1
->ts
.u
.derived
->intmod_sym_id
5352 != c_ptr_2
->ts
.u
.derived
->intmod_sym_id
)))
5354 gfc_error ("Argument C_PTR_2 at %L to C_ASSOCIATED shall have the "
5355 "same type as C_PTR_1: %s instead of %s", &c_ptr_1
->where
,
5356 gfc_typename (&c_ptr_1
->ts
),
5357 gfc_typename (&c_ptr_2
->ts
));
5361 if (c_ptr_2
&& !scalar_check (c_ptr_2
, 1))
5369 gfc_check_c_f_pointer (gfc_expr
*cptr
, gfc_expr
*fptr
, gfc_expr
*shape
)
5371 symbol_attribute attr
;
5374 if (cptr
->ts
.type
!= BT_DERIVED
5375 || cptr
->ts
.u
.derived
->from_intmod
!= INTMOD_ISO_C_BINDING
5376 || cptr
->ts
.u
.derived
->intmod_sym_id
!= ISOCBINDING_PTR
)
5378 gfc_error ("Argument CPTR at %L to C_F_POINTER shall have the "
5379 "type TYPE(C_PTR)", &cptr
->where
);
5383 if (!scalar_check (cptr
, 0))
5386 attr
= gfc_expr_attr (fptr
);
5390 gfc_error ("Argument FPTR at %L to C_F_POINTER must be a pointer",
5395 if (fptr
->ts
.type
== BT_CLASS
)
5397 gfc_error ("FPTR argument at %L to C_F_POINTER shall not be polymorphic",
5402 if (gfc_is_coindexed (fptr
))
5404 gfc_error ("Argument FPTR at %L to C_F_POINTER shall not be "
5405 "coindexed", &fptr
->where
);
5409 if (fptr
->rank
== 0 && shape
)
5411 gfc_error ("Unexpected SHAPE argument at %L to C_F_POINTER with scalar "
5412 "FPTR", &fptr
->where
);
5415 else if (fptr
->rank
&& !shape
)
5417 gfc_error ("Expected SHAPE argument to C_F_POINTER with array "
5418 "FPTR at %L", &fptr
->where
);
5422 if (shape
&& !rank_check (shape
, 2, 1))
5425 if (shape
&& !type_check (shape
, 2, BT_INTEGER
))
5431 if (gfc_array_size (shape
, &size
))
5433 if (mpz_cmp_ui (size
, fptr
->rank
) != 0)
5436 gfc_error ("SHAPE argument at %L to C_F_POINTER must have the same "
5437 "size as the RANK of FPTR", &shape
->where
);
5444 if (fptr
->ts
.type
== BT_CLASS
)
5446 gfc_error ("Polymorphic FPTR at %L to C_F_POINTER", &fptr
->where
);
5450 if (fptr
->rank
> 0 && !is_c_interoperable (fptr
, &msg
, false, true))
5451 return gfc_notify_std (GFC_STD_F2018
, "Noninteroperable array FPTR "
5452 "at %L to C_F_POINTER: %s", &fptr
->where
, msg
);
5459 gfc_check_c_f_procpointer (gfc_expr
*cptr
, gfc_expr
*fptr
)
5461 symbol_attribute attr
;
5463 if (cptr
->ts
.type
!= BT_DERIVED
5464 || cptr
->ts
.u
.derived
->from_intmod
!= INTMOD_ISO_C_BINDING
5465 || cptr
->ts
.u
.derived
->intmod_sym_id
!= ISOCBINDING_FUNPTR
)
5467 gfc_error ("Argument CPTR at %L to C_F_PROCPOINTER shall have the "
5468 "type TYPE(C_FUNPTR)", &cptr
->where
);
5472 if (!scalar_check (cptr
, 0))
5475 attr
= gfc_expr_attr (fptr
);
5477 if (!attr
.proc_pointer
)
5479 gfc_error ("Argument FPTR at %L to C_F_PROCPOINTER shall be a procedure "
5480 "pointer", &fptr
->where
);
5484 if (gfc_is_coindexed (fptr
))
5486 gfc_error ("Argument FPTR at %L to C_F_PROCPOINTER shall not be "
5487 "coindexed", &fptr
->where
);
5491 if (!attr
.is_bind_c
)
5492 return gfc_notify_std (GFC_STD_F2018
, "Noninteroperable procedure "
5493 "pointer at %L to C_F_PROCPOINTER", &fptr
->where
);
5500 gfc_check_c_funloc (gfc_expr
*x
)
5502 symbol_attribute attr
;
5504 if (gfc_is_coindexed (x
))
5506 gfc_error ("Argument X at %L to C_FUNLOC shall not be "
5507 "coindexed", &x
->where
);
5511 attr
= gfc_expr_attr (x
);
5513 if (attr
.function
&& !attr
.proc_pointer
&& x
->expr_type
== EXPR_VARIABLE
5514 && x
->symtree
->n
.sym
== x
->symtree
->n
.sym
->result
)
5515 for (gfc_namespace
*ns
= gfc_current_ns
; ns
; ns
= ns
->parent
)
5516 if (x
->symtree
->n
.sym
== ns
->proc_name
)
5518 gfc_error ("Function result %qs at %L is invalid as X argument "
5519 "to C_FUNLOC", x
->symtree
->n
.sym
->name
, &x
->where
);
5523 if (attr
.flavor
!= FL_PROCEDURE
)
5525 gfc_error ("Argument X at %L to C_FUNLOC shall be a procedure "
5526 "or a procedure pointer", &x
->where
);
5530 if (!attr
.is_bind_c
)
5531 return gfc_notify_std (GFC_STD_F2018
, "Noninteroperable procedure "
5532 "at %L to C_FUNLOC", &x
->where
);
5538 gfc_check_c_loc (gfc_expr
*x
)
5540 symbol_attribute attr
;
5543 if (gfc_is_coindexed (x
))
5545 gfc_error ("Argument X at %L to C_LOC shall not be coindexed", &x
->where
);
5549 if (x
->ts
.type
== BT_CLASS
)
5551 gfc_error ("X argument at %L to C_LOC shall not be polymorphic",
5556 attr
= gfc_expr_attr (x
);
5559 && (x
->expr_type
!= EXPR_VARIABLE
|| !attr
.target
5560 || attr
.flavor
== FL_PARAMETER
))
5562 gfc_error ("Argument X at %L to C_LOC shall have either "
5563 "the POINTER or the TARGET attribute", &x
->where
);
5567 if (x
->ts
.type
== BT_CHARACTER
5568 && gfc_var_strlen (x
) == 0)
5570 gfc_error ("Argument X at %L to C_LOC shall be not be a zero-sized "
5571 "string", &x
->where
);
5575 if (!is_c_interoperable (x
, &msg
, true, false))
5577 if (x
->ts
.type
== BT_CLASS
)
5579 gfc_error ("Argument at %L to C_LOC shall not be polymorphic",
5585 && !gfc_notify_std (GFC_STD_F2018
,
5586 "Noninteroperable array at %L as"
5587 " argument to C_LOC: %s", &x
->where
, msg
))
5590 else if (x
->rank
> 0 && gfc_notification_std (GFC_STD_F2008
))
5592 gfc_array_ref
*ar
= gfc_find_array_ref (x
);
5594 if (ar
->as
->type
!= AS_EXPLICIT
&& ar
->as
->type
!= AS_ASSUMED_SIZE
5595 && !attr
.allocatable
5596 && !gfc_notify_std (GFC_STD_F2008
,
5597 "Array of interoperable type at %L "
5598 "to C_LOC which is nonallocatable and neither "
5599 "assumed size nor explicit size", &x
->where
))
5601 else if (ar
->type
!= AR_FULL
5602 && !gfc_notify_std (GFC_STD_F2008
, "Array section at %L "
5603 "to C_LOC", &x
->where
))
5612 gfc_check_sleep_sub (gfc_expr
*seconds
)
5614 if (!type_check (seconds
, 0, BT_INTEGER
))
5617 if (!scalar_check (seconds
, 0))
5624 gfc_check_sngl (gfc_expr
*a
)
5626 if (!type_check (a
, 0, BT_REAL
))
5629 if ((a
->ts
.kind
!= gfc_default_double_kind
)
5630 && !gfc_notify_std (GFC_STD_GNU
, "non double precision "
5631 "REAL argument to %s intrinsic at %L",
5632 gfc_current_intrinsic
, &a
->where
))
5639 gfc_check_spread (gfc_expr
*source
, gfc_expr
*dim
, gfc_expr
*ncopies
)
5641 if (gfc_invalid_null_arg (source
))
5644 if (source
->rank
>= GFC_MAX_DIMENSIONS
)
5646 gfc_error ("%qs argument of %qs intrinsic at %L must be less "
5647 "than rank %d", gfc_current_intrinsic_arg
[0]->name
,
5648 gfc_current_intrinsic
, &source
->where
, GFC_MAX_DIMENSIONS
);
5656 if (!dim_check (dim
, 1, false))
5659 /* dim_rank_check() does not apply here. */
5661 && dim
->expr_type
== EXPR_CONSTANT
5662 && (mpz_cmp_ui (dim
->value
.integer
, 1) < 0
5663 || mpz_cmp_ui (dim
->value
.integer
, source
->rank
+ 1) > 0))
5665 gfc_error ("%qs argument of %qs intrinsic at %L is not a valid "
5666 "dimension index", gfc_current_intrinsic_arg
[1]->name
,
5667 gfc_current_intrinsic
, &dim
->where
);
5671 if (!type_check (ncopies
, 2, BT_INTEGER
))
5674 if (!scalar_check (ncopies
, 2))
5681 /* Functions for checking FGETC, FPUTC, FGET and FPUT (subroutines and
5685 arg_strlen_is_zero (gfc_expr
*c
, int n
)
5687 if (gfc_var_strlen (c
) == 0)
5689 gfc_error ("%qs argument of %qs intrinsic at %L must have "
5690 "length at least 1", gfc_current_intrinsic_arg
[n
]->name
,
5691 gfc_current_intrinsic
, &c
->where
);
5698 gfc_check_fgetputc_sub (gfc_expr
*unit
, gfc_expr
*c
, gfc_expr
*status
)
5700 if (!type_check (unit
, 0, BT_INTEGER
))
5703 if (!scalar_check (unit
, 0))
5706 if (!type_check (c
, 1, BT_CHARACTER
))
5708 if (!kind_value_check (c
, 1, gfc_default_character_kind
))
5710 if (strcmp (gfc_current_intrinsic
, "fgetc") == 0
5711 && !variable_check (c
, 1, false))
5713 if (arg_strlen_is_zero (c
, 1))
5719 if (!type_check (status
, 2, BT_INTEGER
)
5720 || !kind_value_check (status
, 2, gfc_default_integer_kind
)
5721 || !scalar_check (status
, 2)
5722 || !variable_check (status
, 2, false))
5730 gfc_check_fgetputc (gfc_expr
*unit
, gfc_expr
*c
)
5732 return gfc_check_fgetputc_sub (unit
, c
, NULL
);
5737 gfc_check_fgetput_sub (gfc_expr
*c
, gfc_expr
*status
)
5739 if (!type_check (c
, 0, BT_CHARACTER
))
5741 if (!kind_value_check (c
, 0, gfc_default_character_kind
))
5743 if (strcmp (gfc_current_intrinsic
, "fget") == 0
5744 && !variable_check (c
, 0, false))
5746 if (arg_strlen_is_zero (c
, 0))
5752 if (!type_check (status
, 1, BT_INTEGER
)
5753 || !kind_value_check (status
, 1, gfc_default_integer_kind
)
5754 || !scalar_check (status
, 1)
5755 || !variable_check (status
, 1, false))
5763 gfc_check_fgetput (gfc_expr
*c
)
5765 return gfc_check_fgetput_sub (c
, NULL
);
5770 gfc_check_fseek_sub (gfc_expr
*unit
, gfc_expr
*offset
, gfc_expr
*whence
, gfc_expr
*status
)
5772 if (!type_check (unit
, 0, BT_INTEGER
))
5775 if (!scalar_check (unit
, 0))
5778 if (!type_check (offset
, 1, BT_INTEGER
))
5781 if (!scalar_check (offset
, 1))
5784 if (!type_check (whence
, 2, BT_INTEGER
))
5787 if (!scalar_check (whence
, 2))
5793 if (!type_check (status
, 3, BT_INTEGER
))
5796 if (!kind_value_check (status
, 3, 4))
5799 if (!scalar_check (status
, 3))
5808 gfc_check_fstat (gfc_expr
*unit
, gfc_expr
*array
)
5810 if (!type_check (unit
, 0, BT_INTEGER
))
5813 if (!scalar_check (unit
, 0))
5816 if (!type_check (array
, 1, BT_INTEGER
)
5817 || !kind_value_check (unit
, 0, gfc_default_integer_kind
))
5820 if (!array_check (array
, 1))
5828 gfc_check_fstat_sub (gfc_expr
*unit
, gfc_expr
*array
, gfc_expr
*status
)
5830 if (!type_check (unit
, 0, BT_INTEGER
))
5833 if (!scalar_check (unit
, 0))
5836 if (!type_check (array
, 1, BT_INTEGER
)
5837 || !kind_value_check (array
, 1, gfc_default_integer_kind
))
5840 if (!array_check (array
, 1))
5846 if (!type_check (status
, 2, BT_INTEGER
)
5847 || !kind_value_check (status
, 2, gfc_default_integer_kind
))
5850 if (!scalar_check (status
, 2))
5858 gfc_check_ftell (gfc_expr
*unit
)
5860 if (!type_check (unit
, 0, BT_INTEGER
))
5863 if (!scalar_check (unit
, 0))
5871 gfc_check_ftell_sub (gfc_expr
*unit
, gfc_expr
*offset
)
5873 if (!type_check (unit
, 0, BT_INTEGER
))
5876 if (!scalar_check (unit
, 0))
5879 if (!type_check (offset
, 1, BT_INTEGER
))
5882 if (!scalar_check (offset
, 1))
5890 gfc_check_stat (gfc_expr
*name
, gfc_expr
*array
)
5892 if (!type_check (name
, 0, BT_CHARACTER
))
5894 if (!kind_value_check (name
, 0, gfc_default_character_kind
))
5897 if (!type_check (array
, 1, BT_INTEGER
)
5898 || !kind_value_check (array
, 1, gfc_default_integer_kind
))
5901 if (!array_check (array
, 1))
5909 gfc_check_stat_sub (gfc_expr
*name
, gfc_expr
*array
, gfc_expr
*status
)
5911 if (!type_check (name
, 0, BT_CHARACTER
))
5913 if (!kind_value_check (name
, 0, gfc_default_character_kind
))
5916 if (!type_check (array
, 1, BT_INTEGER
)
5917 || !kind_value_check (array
, 1, gfc_default_integer_kind
))
5920 if (!array_check (array
, 1))
5926 if (!type_check (status
, 2, BT_INTEGER
)
5927 || !kind_value_check (array
, 1, gfc_default_integer_kind
))
5930 if (!scalar_check (status
, 2))
5938 gfc_check_image_index (gfc_expr
*coarray
, gfc_expr
*sub
)
5942 if (flag_coarray
== GFC_FCOARRAY_NONE
)
5944 gfc_fatal_error ("Coarrays disabled at %C, use %<-fcoarray=%> to enable");
5948 if (!coarray_check (coarray
, 0))
5953 gfc_error ("%s argument to IMAGE_INDEX must be a rank one array at %L",
5954 gfc_current_intrinsic_arg
[1]->name
, &sub
->where
);
5958 if (gfc_array_size (sub
, &nelems
))
5960 int corank
= gfc_get_corank (coarray
);
5962 if (mpz_cmp_ui (nelems
, corank
) != 0)
5964 gfc_error ("The number of array elements of the SUB argument to "
5965 "IMAGE_INDEX at %L shall be %d (corank) not %d",
5966 &sub
->where
, corank
, (int) mpz_get_si (nelems
));
5978 gfc_check_num_images (gfc_expr
*distance
, gfc_expr
*failed
)
5980 if (flag_coarray
== GFC_FCOARRAY_NONE
)
5982 gfc_fatal_error ("Coarrays disabled at %C, use %<-fcoarray=%> to enable");
5988 if (!type_check (distance
, 0, BT_INTEGER
))
5991 if (!nonnegative_check ("DISTANCE", distance
))
5994 if (!scalar_check (distance
, 0))
5997 if (!gfc_notify_std (GFC_STD_F2018
, "DISTANCE= argument to "
5998 "NUM_IMAGES at %L", &distance
->where
))
6004 if (!type_check (failed
, 1, BT_LOGICAL
))
6007 if (!scalar_check (failed
, 1))
6010 if (!gfc_notify_std (GFC_STD_F2018
, "FAILED= argument to "
6011 "NUM_IMAGES at %L", &failed
->where
))
6020 gfc_check_team_number (gfc_expr
*team
)
6022 if (flag_coarray
== GFC_FCOARRAY_NONE
)
6024 gfc_fatal_error ("Coarrays disabled at %C, use %<-fcoarray=%> to enable");
6030 if (team
->ts
.type
!= BT_DERIVED
6031 || team
->ts
.u
.derived
->from_intmod
!= INTMOD_ISO_FORTRAN_ENV
6032 || team
->ts
.u
.derived
->intmod_sym_id
!= ISOFORTRAN_TEAM_TYPE
)
6034 gfc_error ("TEAM argument at %L to the intrinsic TEAM_NUMBER "
6035 "shall be of type TEAM_TYPE", &team
->where
);
6047 gfc_check_this_image (gfc_expr
*coarray
, gfc_expr
*dim
, gfc_expr
*distance
)
6049 if (flag_coarray
== GFC_FCOARRAY_NONE
)
6051 gfc_fatal_error ("Coarrays disabled at %C, use %<-fcoarray=%> to enable");
6055 if (coarray
== NULL
&& dim
== NULL
&& distance
== NULL
)
6058 if (dim
!= NULL
&& coarray
== NULL
)
6060 gfc_error ("DIM argument without COARRAY argument not allowed for "
6061 "THIS_IMAGE intrinsic at %L", &dim
->where
);
6065 if (distance
&& (coarray
|| dim
))
6067 gfc_error ("The DISTANCE argument may not be specified together with the "
6068 "COARRAY or DIM argument in intrinsic at %L",
6073 /* Assume that we have "this_image (distance)". */
6074 if (coarray
&& !gfc_is_coarray (coarray
) && coarray
->ts
.type
== BT_INTEGER
)
6078 gfc_error ("Unexpected DIM argument with noncoarray argument at %L",
6087 if (!type_check (distance
, 2, BT_INTEGER
))
6090 if (!nonnegative_check ("DISTANCE", distance
))
6093 if (!scalar_check (distance
, 2))
6096 if (!gfc_notify_std (GFC_STD_F2018
, "DISTANCE= argument to "
6097 "THIS_IMAGE at %L", &distance
->where
))
6103 if (!coarray_check (coarray
, 0))
6108 if (!dim_check (dim
, 1, false))
6111 if (!dim_corank_check (dim
, coarray
))
6118 /* Calculate the sizes for transfer, used by gfc_check_transfer and also
6119 by gfc_simplify_transfer. Return false if we cannot do so. */
6122 gfc_calculate_transfer_sizes (gfc_expr
*source
, gfc_expr
*mold
, gfc_expr
*size
,
6123 size_t *source_size
, size_t *result_size
,
6124 size_t *result_length_p
)
6126 size_t result_elt_size
;
6128 if (source
->expr_type
== EXPR_FUNCTION
)
6131 if (size
&& size
->expr_type
!= EXPR_CONSTANT
)
6134 /* Calculate the size of the source. */
6135 if (!gfc_target_expr_size (source
, source_size
))
6138 /* Determine the size of the element. */
6139 if (!gfc_element_size (mold
, &result_elt_size
))
6142 /* If the storage size of SOURCE is greater than zero and MOLD is an array,
6143 * a scalar with the type and type parameters of MOLD shall not have a
6144 * storage size equal to zero.
6145 * If MOLD is a scalar and SIZE is absent, the result is a scalar.
6146 * If MOLD is an array and SIZE is absent, the result is an array and of
6147 * rank one. Its size is as small as possible such that its physical
6148 * representation is not shorter than that of SOURCE.
6149 * If SIZE is present, the result is an array of rank one and size SIZE.
6151 if (result_elt_size
== 0 && *source_size
> 0 && !size
6152 && mold
->expr_type
== EXPR_ARRAY
)
6154 gfc_error ("%<MOLD%> argument of %<TRANSFER%> intrinsic at %L is an "
6155 "array and shall not have storage size 0 when %<SOURCE%> "
6156 "argument has size greater than 0", &mold
->where
);
6160 if (result_elt_size
== 0 && *source_size
== 0 && !size
)
6163 if (result_length_p
)
6164 *result_length_p
= 0;
6168 if ((result_elt_size
> 0 && (mold
->expr_type
== EXPR_ARRAY
|| mold
->rank
))
6174 result_length
= (size_t)mpz_get_ui (size
->value
.integer
);
6177 result_length
= *source_size
/ result_elt_size
;
6178 if (result_length
* result_elt_size
< *source_size
)
6182 *result_size
= result_length
* result_elt_size
;
6183 if (result_length_p
)
6184 *result_length_p
= result_length
;
6187 *result_size
= result_elt_size
;
6194 gfc_check_transfer (gfc_expr
*source
, gfc_expr
*mold
, gfc_expr
*size
)
6199 if (gfc_invalid_null_arg (source
))
6202 /* SOURCE shall be a scalar or array of any type. */
6203 if (source
->ts
.type
== BT_PROCEDURE
6204 && source
->symtree
->n
.sym
->attr
.subroutine
== 1)
6206 gfc_error ("%<SOURCE%> argument of %<TRANSFER%> intrinsic at %L "
6207 "must not be a %s", &source
->where
,
6208 gfc_basic_typename (source
->ts
.type
));
6212 if (source
->ts
.type
== BT_BOZ
&& illegal_boz_arg (source
))
6215 if (mold
->ts
.type
== BT_BOZ
&& illegal_boz_arg (mold
))
6218 if (gfc_invalid_null_arg (mold
))
6221 /* MOLD shall be a scalar or array of any type. */
6222 if (mold
->ts
.type
== BT_PROCEDURE
6223 && mold
->symtree
->n
.sym
->attr
.subroutine
== 1)
6225 gfc_error ("%<MOLD%> argument of %<TRANSFER%> intrinsic at %L "
6226 "must not be a %s", &mold
->where
,
6227 gfc_basic_typename (mold
->ts
.type
));
6231 if (mold
->ts
.type
== BT_HOLLERITH
)
6233 gfc_error ("%<MOLD%> argument of %<TRANSFER%> intrinsic at %L must not be"
6234 " %s", &mold
->where
, gfc_basic_typename (BT_HOLLERITH
));
6238 /* SIZE (optional) shall be an integer scalar. The corresponding actual
6239 argument shall not be an optional dummy argument. */
6242 if (!type_check (size
, 2, BT_INTEGER
))
6244 if (size
->ts
.type
== BT_BOZ
)
6249 if (!scalar_check (size
, 2))
6252 if (!nonoptional_check (size
, 2))
6256 if (!warn_surprising
)
6259 /* If we can't calculate the sizes, we cannot check any more.
6260 Return true for that case. */
6262 if (!gfc_calculate_transfer_sizes (source
, mold
, size
, &source_size
,
6263 &result_size
, NULL
))
6266 if (source_size
< result_size
)
6267 gfc_warning (OPT_Wsurprising
,
6268 "Intrinsic TRANSFER at %L has partly undefined result: "
6269 "source size %ld < result size %ld", &source
->where
,
6270 (long) source_size
, (long) result_size
);
6277 gfc_check_transpose (gfc_expr
*matrix
)
6279 if (!rank_check (matrix
, 0, 2))
6287 gfc_check_ubound (gfc_expr
*array
, gfc_expr
*dim
, gfc_expr
*kind
)
6289 if (!array_check (array
, 0))
6292 if (!dim_check (dim
, 1, false))
6295 if (!dim_rank_check (dim
, array
, 0))
6298 if (!kind_check (kind
, 2, BT_INTEGER
))
6300 if (kind
&& !gfc_notify_std (GFC_STD_F2003
, "%qs intrinsic "
6301 "with KIND argument at %L",
6302 gfc_current_intrinsic
, &kind
->where
))
6310 gfc_check_ucobound (gfc_expr
*coarray
, gfc_expr
*dim
, gfc_expr
*kind
)
6312 if (flag_coarray
== GFC_FCOARRAY_NONE
)
6314 gfc_fatal_error ("Coarrays disabled at %C, use %<-fcoarray=%> to enable");
6318 if (!coarray_check (coarray
, 0))
6323 if (!dim_check (dim
, 1, false))
6326 if (!dim_corank_check (dim
, coarray
))
6330 if (!kind_check (kind
, 2, BT_INTEGER
))
6338 gfc_check_unpack (gfc_expr
*vector
, gfc_expr
*mask
, gfc_expr
*field
)
6342 if (!rank_check (vector
, 0, 1))
6345 if (!array_check (mask
, 1))
6348 if (!type_check (mask
, 1, BT_LOGICAL
))
6351 if (!same_type_check (vector
, 0, field
, 2))
6354 if (mask
->expr_type
== EXPR_ARRAY
6355 && gfc_array_size (vector
, &vector_size
))
6357 int mask_true_count
= 0;
6358 gfc_constructor
*mask_ctor
;
6359 mask_ctor
= gfc_constructor_first (mask
->value
.constructor
);
6362 if (mask_ctor
->expr
->expr_type
!= EXPR_CONSTANT
)
6364 mask_true_count
= 0;
6368 if (mask_ctor
->expr
->value
.logical
)
6371 mask_ctor
= gfc_constructor_next (mask_ctor
);
6374 if (mpz_get_si (vector_size
) < mask_true_count
)
6376 gfc_error ("%qs argument of %qs intrinsic at %L must "
6377 "provide at least as many elements as there "
6378 "are .TRUE. values in %qs (%ld/%d)",
6379 gfc_current_intrinsic_arg
[0]->name
, gfc_current_intrinsic
,
6380 &vector
->where
, gfc_current_intrinsic_arg
[1]->name
,
6381 mpz_get_si (vector_size
), mask_true_count
);
6385 mpz_clear (vector_size
);
6388 if (mask
->rank
!= field
->rank
&& field
->rank
!= 0)
6390 gfc_error ("%qs argument of %qs intrinsic at %L must have "
6391 "the same rank as %qs or be a scalar",
6392 gfc_current_intrinsic_arg
[2]->name
, gfc_current_intrinsic
,
6393 &field
->where
, gfc_current_intrinsic_arg
[1]->name
);
6397 if (mask
->rank
== field
->rank
)
6400 for (i
= 0; i
< field
->rank
; i
++)
6401 if (! identical_dimen_shape (mask
, i
, field
, i
))
6403 gfc_error ("%qs and %qs arguments of %qs intrinsic at %L "
6404 "must have identical shape.",
6405 gfc_current_intrinsic_arg
[2]->name
,
6406 gfc_current_intrinsic_arg
[1]->name
, gfc_current_intrinsic
,
6416 gfc_check_verify (gfc_expr
*x
, gfc_expr
*y
, gfc_expr
*z
, gfc_expr
*kind
)
6418 if (!type_check (x
, 0, BT_CHARACTER
))
6421 if (!same_type_check (x
, 0, y
, 1))
6424 if (z
!= NULL
&& !type_check (z
, 2, BT_LOGICAL
))
6427 if (!kind_check (kind
, 3, BT_INTEGER
))
6429 if (kind
&& !gfc_notify_std (GFC_STD_F2003
, "%qs intrinsic "
6430 "with KIND argument at %L",
6431 gfc_current_intrinsic
, &kind
->where
))
6439 gfc_check_trim (gfc_expr
*x
)
6441 if (!type_check (x
, 0, BT_CHARACTER
))
6444 if (gfc_invalid_null_arg (x
))
6447 if (!scalar_check (x
, 0))
6455 gfc_check_ttynam (gfc_expr
*unit
)
6457 if (!scalar_check (unit
, 0))
6460 if (!type_check (unit
, 0, BT_INTEGER
))
6467 /************* Check functions for intrinsic subroutines *************/
6470 gfc_check_cpu_time (gfc_expr
*time
)
6472 if (!scalar_check (time
, 0))
6475 if (!type_check (time
, 0, BT_REAL
))
6478 if (!variable_check (time
, 0, false))
6486 gfc_check_date_and_time (gfc_expr
*date
, gfc_expr
*time
,
6487 gfc_expr
*zone
, gfc_expr
*values
)
6491 if (!type_check (date
, 0, BT_CHARACTER
))
6493 if (!kind_value_check (date
, 0, gfc_default_character_kind
))
6495 if (!scalar_check (date
, 0))
6497 if (!variable_check (date
, 0, false))
6503 if (!type_check (time
, 1, BT_CHARACTER
))
6505 if (!kind_value_check (time
, 1, gfc_default_character_kind
))
6507 if (!scalar_check (time
, 1))
6509 if (!variable_check (time
, 1, false))
6515 if (!type_check (zone
, 2, BT_CHARACTER
))
6517 if (!kind_value_check (zone
, 2, gfc_default_character_kind
))
6519 if (!scalar_check (zone
, 2))
6521 if (!variable_check (zone
, 2, false))
6527 if (!type_check (values
, 3, BT_INTEGER
))
6529 if (!array_check (values
, 3))
6531 if (!rank_check (values
, 3, 1))
6533 if (!variable_check (values
, 3, false))
6542 gfc_check_mvbits (gfc_expr
*from
, gfc_expr
*frompos
, gfc_expr
*len
,
6543 gfc_expr
*to
, gfc_expr
*topos
)
6545 if (!type_check (from
, 0, BT_INTEGER
))
6548 if (!type_check (frompos
, 1, BT_INTEGER
))
6551 if (!type_check (len
, 2, BT_INTEGER
))
6554 if (!same_type_check (from
, 0, to
, 3))
6557 if (!variable_check (to
, 3, false))
6560 if (!type_check (topos
, 4, BT_INTEGER
))
6563 if (!nonnegative_check ("frompos", frompos
))
6566 if (!nonnegative_check ("topos", topos
))
6569 if (!nonnegative_check ("len", len
))
6572 if (!less_than_bitsize2 ("from", from
, "frompos", frompos
, "len", len
))
6575 if (!less_than_bitsize2 ("to", to
, "topos", topos
, "len", len
))
6582 /* Check the arguments for RANDOM_INIT. */
6585 gfc_check_random_init (gfc_expr
*repeatable
, gfc_expr
*image_distinct
)
6587 if (!type_check (repeatable
, 0, BT_LOGICAL
))
6590 if (!scalar_check (repeatable
, 0))
6593 if (!type_check (image_distinct
, 1, BT_LOGICAL
))
6596 if (!scalar_check (image_distinct
, 1))
6604 gfc_check_random_number (gfc_expr
*harvest
)
6606 if (!type_check (harvest
, 0, BT_REAL
))
6609 if (!variable_check (harvest
, 0, false))
6617 gfc_check_random_seed (gfc_expr
*size
, gfc_expr
*put
, gfc_expr
*get
)
6619 unsigned int nargs
= 0, seed_size
;
6620 locus
*where
= NULL
;
6621 mpz_t put_size
, get_size
;
6623 /* Keep the number of bytes in sync with master_state in
6624 libgfortran/intrinsics/random.c. */
6625 seed_size
= 32 / gfc_default_integer_kind
;
6629 if (size
->expr_type
!= EXPR_VARIABLE
6630 || !size
->symtree
->n
.sym
->attr
.optional
)
6633 if (!scalar_check (size
, 0))
6636 if (!type_check (size
, 0, BT_INTEGER
))
6639 if (!variable_check (size
, 0, false))
6642 if (!kind_value_check (size
, 0, gfc_default_integer_kind
))
6648 if (put
->expr_type
!= EXPR_VARIABLE
6649 || !put
->symtree
->n
.sym
->attr
.optional
)
6652 where
= &put
->where
;
6655 if (!array_check (put
, 1))
6658 if (!rank_check (put
, 1, 1))
6661 if (!type_check (put
, 1, BT_INTEGER
))
6664 if (!kind_value_check (put
, 1, gfc_default_integer_kind
))
6667 if (gfc_array_size (put
, &put_size
)
6668 && mpz_get_ui (put_size
) < seed_size
)
6669 gfc_error ("Size of %qs argument of %qs intrinsic at %L "
6670 "too small (%i/%i)",
6671 gfc_current_intrinsic_arg
[1]->name
, gfc_current_intrinsic
,
6672 &put
->where
, (int) mpz_get_ui (put_size
), seed_size
);
6677 if (get
->expr_type
!= EXPR_VARIABLE
6678 || !get
->symtree
->n
.sym
->attr
.optional
)
6681 where
= &get
->where
;
6684 if (!array_check (get
, 2))
6687 if (!rank_check (get
, 2, 1))
6690 if (!type_check (get
, 2, BT_INTEGER
))
6693 if (!variable_check (get
, 2, false))
6696 if (!kind_value_check (get
, 2, gfc_default_integer_kind
))
6699 if (gfc_array_size (get
, &get_size
)
6700 && mpz_get_ui (get_size
) < seed_size
)
6701 gfc_error ("Size of %qs argument of %qs intrinsic at %L "
6702 "too small (%i/%i)",
6703 gfc_current_intrinsic_arg
[2]->name
, gfc_current_intrinsic
,
6704 &get
->where
, (int) mpz_get_ui (get_size
), seed_size
);
6707 /* RANDOM_SEED may not have more than one non-optional argument. */
6709 gfc_error ("Too many arguments to %s at %L", gfc_current_intrinsic
, where
);
6715 gfc_check_fe_runtime_error (gfc_actual_arglist
*a
)
6719 int num_percent
, nargs
;
6722 if (e
->expr_type
!= EXPR_CONSTANT
)
6725 len
= e
->value
.character
.length
;
6726 if (e
->value
.character
.string
[len
-1] != '\0')
6727 gfc_internal_error ("fe_runtime_error string must be null terminated");
6730 for (i
=0; i
<len
-1; i
++)
6731 if (e
->value
.character
.string
[i
] == '%')
6735 for (; a
; a
= a
->next
)
6738 if (nargs
-1 != num_percent
)
6739 gfc_internal_error ("fe_runtime_error: Wrong number of arguments (%d instead of %d)",
6740 nargs
, num_percent
++);
6746 gfc_check_second_sub (gfc_expr
*time
)
6748 if (!scalar_check (time
, 0))
6751 if (!type_check (time
, 0, BT_REAL
))
6754 if (!kind_value_check (time
, 0, 4))
6761 /* COUNT and COUNT_MAX of SYSTEM_CLOCK are scalar, default-kind integer
6762 variables in Fortran 95. In Fortran 2003 and later, they can be of any
6763 kind, and COUNT_RATE can be of type real. Note, count, count_rate, and
6764 count_max are all optional arguments */
6767 gfc_check_system_clock (gfc_expr
*count
, gfc_expr
*count_rate
,
6768 gfc_expr
*count_max
)
6772 if (!scalar_check (count
, 0))
6775 if (!type_check (count
, 0, BT_INTEGER
))
6778 if (count
->ts
.kind
!= gfc_default_integer_kind
6779 && !gfc_notify_std (GFC_STD_F2003
, "COUNT argument to "
6780 "SYSTEM_CLOCK at %L has non-default kind",
6784 if (!variable_check (count
, 0, false))
6788 if (count_rate
!= NULL
)
6790 if (!scalar_check (count_rate
, 1))
6793 if (!variable_check (count_rate
, 1, false))
6796 if (count_rate
->ts
.type
== BT_REAL
)
6798 if (!gfc_notify_std (GFC_STD_F2003
, "Real COUNT_RATE argument to "
6799 "SYSTEM_CLOCK at %L", &count_rate
->where
))
6804 if (!type_check (count_rate
, 1, BT_INTEGER
))
6807 if (count_rate
->ts
.kind
!= gfc_default_integer_kind
6808 && !gfc_notify_std (GFC_STD_F2003
, "COUNT_RATE argument to "
6809 "SYSTEM_CLOCK at %L has non-default kind",
6810 &count_rate
->where
))
6816 if (count_max
!= NULL
)
6818 if (!scalar_check (count_max
, 2))
6821 if (!type_check (count_max
, 2, BT_INTEGER
))
6824 if (count_max
->ts
.kind
!= gfc_default_integer_kind
6825 && !gfc_notify_std (GFC_STD_F2003
, "COUNT_MAX argument to "
6826 "SYSTEM_CLOCK at %L has non-default kind",
6830 if (!variable_check (count_max
, 2, false))
6839 gfc_check_irand (gfc_expr
*x
)
6844 if (!scalar_check (x
, 0))
6847 if (!type_check (x
, 0, BT_INTEGER
))
6850 if (!kind_value_check (x
, 0, 4))
6858 gfc_check_alarm_sub (gfc_expr
*seconds
, gfc_expr
*handler
, gfc_expr
*status
)
6860 if (!scalar_check (seconds
, 0))
6862 if (!type_check (seconds
, 0, BT_INTEGER
))
6865 if (!int_or_proc_check (handler
, 1))
6867 if (handler
->ts
.type
== BT_INTEGER
&& !scalar_check (handler
, 1))
6873 if (!scalar_check (status
, 2))
6875 if (!type_check (status
, 2, BT_INTEGER
))
6877 if (!kind_value_check (status
, 2, gfc_default_integer_kind
))
6885 gfc_check_rand (gfc_expr
*x
)
6890 if (!scalar_check (x
, 0))
6893 if (!type_check (x
, 0, BT_INTEGER
))
6896 if (!kind_value_check (x
, 0, 4))
6904 gfc_check_srand (gfc_expr
*x
)
6906 if (!scalar_check (x
, 0))
6909 if (!type_check (x
, 0, BT_INTEGER
))
6912 if (!kind_value_check (x
, 0, 4))
6920 gfc_check_ctime_sub (gfc_expr
*time
, gfc_expr
*result
)
6922 if (!scalar_check (time
, 0))
6924 if (!type_check (time
, 0, BT_INTEGER
))
6927 if (!type_check (result
, 1, BT_CHARACTER
))
6929 if (!kind_value_check (result
, 1, gfc_default_character_kind
))
6937 gfc_check_dtime_etime (gfc_expr
*x
)
6939 if (!array_check (x
, 0))
6942 if (!rank_check (x
, 0, 1))
6945 if (!variable_check (x
, 0, false))
6948 if (!type_check (x
, 0, BT_REAL
))
6951 if (!kind_value_check (x
, 0, 4))
6959 gfc_check_dtime_etime_sub (gfc_expr
*values
, gfc_expr
*time
)
6961 if (!array_check (values
, 0))
6964 if (!rank_check (values
, 0, 1))
6967 if (!variable_check (values
, 0, false))
6970 if (!type_check (values
, 0, BT_REAL
))
6973 if (!kind_value_check (values
, 0, 4))
6976 if (!scalar_check (time
, 1))
6979 if (!type_check (time
, 1, BT_REAL
))
6982 if (!kind_value_check (time
, 1, 4))
6990 gfc_check_fdate_sub (gfc_expr
*date
)
6992 if (!type_check (date
, 0, BT_CHARACTER
))
6994 if (!kind_value_check (date
, 0, gfc_default_character_kind
))
7002 gfc_check_gerror (gfc_expr
*msg
)
7004 if (!type_check (msg
, 0, BT_CHARACTER
))
7006 if (!kind_value_check (msg
, 0, gfc_default_character_kind
))
7014 gfc_check_getcwd_sub (gfc_expr
*cwd
, gfc_expr
*status
)
7016 if (!type_check (cwd
, 0, BT_CHARACTER
))
7018 if (!kind_value_check (cwd
, 0, gfc_default_character_kind
))
7024 if (!scalar_check (status
, 1))
7027 if (!type_check (status
, 1, BT_INTEGER
))
7035 gfc_check_getarg (gfc_expr
*pos
, gfc_expr
*value
)
7037 if (!type_check (pos
, 0, BT_INTEGER
))
7040 if (pos
->ts
.kind
> gfc_default_integer_kind
)
7042 gfc_error ("%qs argument of %qs intrinsic at %L must be of a kind "
7043 "not wider than the default kind (%d)",
7044 gfc_current_intrinsic_arg
[0]->name
, gfc_current_intrinsic
,
7045 &pos
->where
, gfc_default_integer_kind
);
7049 if (!type_check (value
, 1, BT_CHARACTER
))
7051 if (!kind_value_check (value
, 1, gfc_default_character_kind
))
7059 gfc_check_getlog (gfc_expr
*msg
)
7061 if (!type_check (msg
, 0, BT_CHARACTER
))
7063 if (!kind_value_check (msg
, 0, gfc_default_character_kind
))
7071 gfc_check_exit (gfc_expr
*status
)
7076 if (!type_check (status
, 0, BT_INTEGER
))
7079 if (!scalar_check (status
, 0))
7087 gfc_check_flush (gfc_expr
*unit
)
7092 if (!type_check (unit
, 0, BT_INTEGER
))
7095 if (!scalar_check (unit
, 0))
7103 gfc_check_free (gfc_expr
*i
)
7105 if (!type_check (i
, 0, BT_INTEGER
))
7108 if (!scalar_check (i
, 0))
7116 gfc_check_hostnm (gfc_expr
*name
)
7118 if (!type_check (name
, 0, BT_CHARACTER
))
7120 if (!kind_value_check (name
, 0, gfc_default_character_kind
))
7128 gfc_check_hostnm_sub (gfc_expr
*name
, gfc_expr
*status
)
7130 if (!type_check (name
, 0, BT_CHARACTER
))
7132 if (!kind_value_check (name
, 0, gfc_default_character_kind
))
7138 if (!scalar_check (status
, 1))
7141 if (!type_check (status
, 1, BT_INTEGER
))
7149 gfc_check_itime_idate (gfc_expr
*values
)
7151 if (!array_check (values
, 0))
7154 if (!rank_check (values
, 0, 1))
7157 if (!variable_check (values
, 0, false))
7160 if (!type_check (values
, 0, BT_INTEGER
))
7163 if (!kind_value_check (values
, 0, gfc_default_integer_kind
))
7171 gfc_check_ltime_gmtime (gfc_expr
*time
, gfc_expr
*values
)
7173 if (!type_check (time
, 0, BT_INTEGER
))
7176 if (!kind_value_check (time
, 0, gfc_default_integer_kind
))
7179 if (!scalar_check (time
, 0))
7182 if (!array_check (values
, 1))
7185 if (!rank_check (values
, 1, 1))
7188 if (!variable_check (values
, 1, false))
7191 if (!type_check (values
, 1, BT_INTEGER
))
7194 if (!kind_value_check (values
, 1, gfc_default_integer_kind
))
7202 gfc_check_ttynam_sub (gfc_expr
*unit
, gfc_expr
*name
)
7204 if (!scalar_check (unit
, 0))
7207 if (!type_check (unit
, 0, BT_INTEGER
))
7210 if (!type_check (name
, 1, BT_CHARACTER
))
7212 if (!kind_value_check (name
, 1, gfc_default_character_kind
))
7220 gfc_check_is_contiguous (gfc_expr
*array
)
7222 if (array
->expr_type
== EXPR_NULL
)
7224 gfc_error ("Actual argument at %L of %qs intrinsic shall be an "
7225 "associated pointer", &array
->where
, gfc_current_intrinsic
);
7229 if (!array_check (array
, 0))
7237 gfc_check_isatty (gfc_expr
*unit
)
7242 if (!type_check (unit
, 0, BT_INTEGER
))
7245 if (!scalar_check (unit
, 0))
7253 gfc_check_isnan (gfc_expr
*x
)
7255 if (!type_check (x
, 0, BT_REAL
))
7263 gfc_check_perror (gfc_expr
*string
)
7265 if (!type_check (string
, 0, BT_CHARACTER
))
7267 if (!kind_value_check (string
, 0, gfc_default_character_kind
))
7275 gfc_check_umask (gfc_expr
*mask
)
7277 if (!type_check (mask
, 0, BT_INTEGER
))
7280 if (!scalar_check (mask
, 0))
7288 gfc_check_umask_sub (gfc_expr
*mask
, gfc_expr
*old
)
7290 if (!type_check (mask
, 0, BT_INTEGER
))
7293 if (!scalar_check (mask
, 0))
7299 if (!scalar_check (old
, 1))
7302 if (!type_check (old
, 1, BT_INTEGER
))
7310 gfc_check_unlink (gfc_expr
*name
)
7312 if (!type_check (name
, 0, BT_CHARACTER
))
7314 if (!kind_value_check (name
, 0, gfc_default_character_kind
))
7322 gfc_check_unlink_sub (gfc_expr
*name
, gfc_expr
*status
)
7324 if (!type_check (name
, 0, BT_CHARACTER
))
7326 if (!kind_value_check (name
, 0, gfc_default_character_kind
))
7332 if (!scalar_check (status
, 1))
7335 if (!type_check (status
, 1, BT_INTEGER
))
7343 gfc_check_signal (gfc_expr
*number
, gfc_expr
*handler
)
7345 if (!scalar_check (number
, 0))
7347 if (!type_check (number
, 0, BT_INTEGER
))
7350 if (!int_or_proc_check (handler
, 1))
7352 if (handler
->ts
.type
== BT_INTEGER
&& !scalar_check (handler
, 1))
7360 gfc_check_signal_sub (gfc_expr
*number
, gfc_expr
*handler
, gfc_expr
*status
)
7362 if (!scalar_check (number
, 0))
7364 if (!type_check (number
, 0, BT_INTEGER
))
7367 if (!int_or_proc_check (handler
, 1))
7369 if (handler
->ts
.type
== BT_INTEGER
&& !scalar_check (handler
, 1))
7375 if (!type_check (status
, 2, BT_INTEGER
))
7377 if (!scalar_check (status
, 2))
7385 gfc_check_system_sub (gfc_expr
*cmd
, gfc_expr
*status
)
7387 if (!type_check (cmd
, 0, BT_CHARACTER
))
7389 if (!kind_value_check (cmd
, 0, gfc_default_character_kind
))
7392 if (!scalar_check (status
, 1))
7395 if (!type_check (status
, 1, BT_INTEGER
))
7398 if (!kind_value_check (status
, 1, gfc_default_integer_kind
))
7405 /* This is used for the GNU intrinsics AND, OR and XOR. */
7407 gfc_check_and (gfc_expr
*i
, gfc_expr
*j
)
7409 if (i
->ts
.type
!= BT_INTEGER
7410 && i
->ts
.type
!= BT_LOGICAL
7411 && i
->ts
.type
!= BT_BOZ
)
7413 gfc_error ("%qs argument of %qs intrinsic at %L must be INTEGER, "
7414 "LOGICAL, or a BOZ literal constant",
7415 gfc_current_intrinsic_arg
[0]->name
,
7416 gfc_current_intrinsic
, &i
->where
);
7420 if (j
->ts
.type
!= BT_INTEGER
7421 && j
->ts
.type
!= BT_LOGICAL
7422 && j
->ts
.type
!= BT_BOZ
)
7424 gfc_error ("%qs argument of %qs intrinsic at %L must be INTEGER, "
7425 "LOGICAL, or a BOZ literal constant",
7426 gfc_current_intrinsic_arg
[1]->name
,
7427 gfc_current_intrinsic
, &j
->where
);
7431 /* i and j cannot both be BOZ literal constants. */
7432 if (!boz_args_check (i
, j
))
7435 /* If i is BOZ and j is integer, convert i to type of j. */
7436 if (i
->ts
.type
== BT_BOZ
)
7438 if (j
->ts
.type
!= BT_INTEGER
)
7440 gfc_error ("%qs argument of %qs intrinsic at %L must be INTEGER",
7441 gfc_current_intrinsic_arg
[1]->name
,
7442 gfc_current_intrinsic
, &j
->where
);
7446 if (!gfc_boz2int (i
, j
->ts
.kind
))
7450 /* If j is BOZ and i is integer, convert j to type of i. */
7451 if (j
->ts
.type
== BT_BOZ
)
7453 if (i
->ts
.type
!= BT_INTEGER
)
7455 gfc_error ("%qs argument of %qs intrinsic at %L must be INTEGER",
7456 gfc_current_intrinsic_arg
[0]->name
,
7457 gfc_current_intrinsic
, &j
->where
);
7461 if (!gfc_boz2int (j
, i
->ts
.kind
))
7465 if (!same_type_check (i
, 0, j
, 1, false))
7468 if (!scalar_check (i
, 0))
7471 if (!scalar_check (j
, 1))
7479 gfc_check_storage_size (gfc_expr
*a
, gfc_expr
*kind
)
7482 if (a
->expr_type
== EXPR_NULL
)
7484 gfc_error ("Intrinsic function NULL at %L cannot be an actual "
7485 "argument to STORAGE_SIZE, because it returns a "
7486 "disassociated pointer", &a
->where
);
7490 if (a
->ts
.type
== BT_ASSUMED
)
7492 gfc_error ("%qs argument of %qs intrinsic at %L shall not be TYPE(*)",
7493 gfc_current_intrinsic_arg
[0]->name
, gfc_current_intrinsic
,
7498 if (a
->ts
.type
== BT_PROCEDURE
)
7500 gfc_error ("%qs argument of %qs intrinsic at %L shall not be a "
7501 "procedure", gfc_current_intrinsic_arg
[0]->name
,
7502 gfc_current_intrinsic
, &a
->where
);
7506 if (a
->ts
.type
== BT_BOZ
&& illegal_boz_arg (a
))
7512 if (!type_check (kind
, 1, BT_INTEGER
))
7515 if (!scalar_check (kind
, 1))
7518 if (kind
->expr_type
!= EXPR_CONSTANT
)
7520 gfc_error ("%qs argument of %qs intrinsic at %L must be a constant",
7521 gfc_current_intrinsic_arg
[1]->name
, gfc_current_intrinsic
,