Branch data Line data Source code
1 : : /* Check functions
2 : : Copyright (C) 2002-2024 Free Software Foundation, Inc.
3 : : Contributed by Andy Vaught & Katherine Holcomb
4 : :
5 : : This file is part of GCC.
6 : :
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
10 : : version.
11 : :
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
15 : : for more details.
16 : :
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/>. */
20 : :
21 : :
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. */
27 : :
28 : : #include "config.h"
29 : : #include "system.h"
30 : : #include "coretypes.h"
31 : : #include "options.h"
32 : : #include "gfortran.h"
33 : : #include "intrinsic.h"
34 : : #include "constructor.h"
35 : : #include "target-memory.h"
36 : :
37 : :
38 : : /* Reset a BOZ to a zero value. This is used to prevent run-on errors
39 : : from resolve.cc(resolve_function). */
40 : :
41 : : static void
42 : 39 : reset_boz (gfc_expr *x)
43 : : {
44 : : /* Clear boz info. */
45 : 39 : x->boz.rdx = 0;
46 : 39 : x->boz.len = 0;
47 : 39 : free (x->boz.str);
48 : :
49 : 39 : x->ts.type = BT_INTEGER;
50 : 39 : x->ts.kind = gfc_default_integer_kind;
51 : 39 : mpz_init (x->value.integer);
52 : 39 : mpz_set_ui (x->value.integer, 0);
53 : 39 : }
54 : :
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. */
60 : :
61 : : bool
62 : 217 : gfc_invalid_boz (const char *msg, locus *loc)
63 : : {
64 : 217 : if (flag_allow_invalid_boz)
65 : : {
66 : 204 : gfc_warning (0, msg, loc);
67 : 204 : return false;
68 : : }
69 : :
70 : 13 : const char *hint = _(" [see %<-fno-allow-invalid-boz%>]");
71 : 13 : size_t len = strlen (msg) + strlen (hint) + 1;
72 : 13 : char *msg2 = (char *) alloca (len);
73 : 13 : strcpy (msg2, msg);
74 : 13 : strcat (msg2, hint);
75 : 13 : gfc_error (msg2, loc);
76 : 13 : return true;
77 : : }
78 : :
79 : :
80 : : /* Issue an error for an illegal BOZ argument. */
81 : :
82 : : static bool
83 : 1798 : illegal_boz_arg (gfc_expr *x)
84 : : {
85 : 1798 : if (x->ts.type == BT_BOZ)
86 : : {
87 : 4 : gfc_error ("BOZ literal constant at %L cannot be an actual argument "
88 : : "to %qs", &x->where, gfc_current_intrinsic);
89 : 4 : reset_boz (x);
90 : 4 : return true;
91 : : }
92 : :
93 : : return false;
94 : : }
95 : :
96 : : /* Some procedures take two arguments such that both cannot be BOZ. */
97 : :
98 : : static bool
99 : 6822 : boz_args_check(gfc_expr *i, gfc_expr *j)
100 : : {
101 : 6822 : if (i->ts.type == BT_BOZ && j->ts.type == BT_BOZ)
102 : : {
103 : 14 : gfc_error ("Arguments of %qs at %L and %L cannot both be BOZ "
104 : : "literal constants", gfc_current_intrinsic, &i->where,
105 : : &j->where);
106 : 14 : reset_boz (i);
107 : 14 : reset_boz (j);
108 : 14 : return false;
109 : :
110 : : }
111 : :
112 : : return true;
113 : : }
114 : :
115 : :
116 : : /* Check that a BOZ is a constant. */
117 : :
118 : : static bool
119 : 2577 : is_boz_constant (gfc_expr *a)
120 : : {
121 : 0 : if (a->expr_type != EXPR_CONSTANT)
122 : : {
123 : 0 : gfc_error ("Invalid use of BOZ literal constant at %L", &a->where);
124 : 0 : return false;
125 : : }
126 : :
127 : : return true;
128 : : }
129 : :
130 : :
131 : : /* Convert a octal string into a binary string. This is used in the
132 : : fallback conversion of an octal string to a REAL. */
133 : :
134 : : static char *
135 : 0 : oct2bin(int nbits, char *oct)
136 : : {
137 : 0 : const char bits[8][5] = {
138 : : "000", "001", "010", "011", "100", "101", "110", "111"};
139 : :
140 : 0 : char *buf, *bufp;
141 : 0 : int i, j, n;
142 : :
143 : 0 : j = nbits + 1;
144 : 0 : if (nbits == 64) j++;
145 : :
146 : 0 : bufp = buf = XCNEWVEC (char, j + 1);
147 : 0 : memset (bufp, 0, j + 1);
148 : :
149 : 0 : n = strlen (oct);
150 : 0 : for (i = 0; i < n; i++, oct++)
151 : : {
152 : 0 : j = *oct - 48;
153 : 0 : strcpy (bufp, &bits[j][0]);
154 : 0 : bufp += 3;
155 : : }
156 : :
157 : 0 : bufp = XCNEWVEC (char, nbits + 1);
158 : 0 : if (nbits == 64)
159 : 0 : strcpy (bufp, buf + 2);
160 : : else
161 : 0 : strcpy (bufp, buf + 1);
162 : :
163 : 0 : free (buf);
164 : :
165 : 0 : return bufp;
166 : : }
167 : :
168 : :
169 : : /* Convert a hexidecimal string into a binary string. This is used in the
170 : : fallback conversion of a hexidecimal string to a REAL. */
171 : :
172 : : static char *
173 : 0 : hex2bin(int nbits, char *hex)
174 : : {
175 : 0 : const char bits[16][5] = {
176 : : "0000", "0001", "0010", "0011", "0100", "0101", "0110", "0111",
177 : : "1000", "1001", "1010", "1011", "1100", "1101", "1110", "1111"};
178 : :
179 : 0 : char *buf, *bufp;
180 : 0 : int i, j, n;
181 : :
182 : 0 : bufp = buf = XCNEWVEC (char, nbits + 1);
183 : 0 : memset (bufp, 0, nbits + 1);
184 : :
185 : 0 : n = strlen (hex);
186 : 0 : for (i = 0; i < n; i++, hex++)
187 : : {
188 : 0 : j = *hex;
189 : 0 : if (j > 47 && j < 58)
190 : 0 : j -= 48;
191 : 0 : else if (j > 64 && j < 71)
192 : 0 : j -= 55;
193 : 0 : else if (j > 96 && j < 103)
194 : 0 : j -= 87;
195 : : else
196 : 0 : gcc_unreachable ();
197 : :
198 : 0 : strcpy (bufp, &bits[j][0]);
199 : 0 : bufp += 4;
200 : : }
201 : :
202 : 0 : return buf;
203 : : }
204 : :
205 : :
206 : : /* Fallback conversion of a BOZ string to REAL. */
207 : :
208 : : static void
209 : 0 : bin2real (gfc_expr *x, int kind)
210 : : {
211 : 0 : char buf[114], *sp;
212 : 0 : int b, i, ie, t, w;
213 : 0 : bool sgn;
214 : 0 : mpz_t em;
215 : :
216 : 0 : i = gfc_validate_kind (BT_REAL, kind, false);
217 : 0 : t = gfc_real_kinds[i].digits - 1;
218 : :
219 : : /* Number of bits in the exponent. */
220 : 0 : if (gfc_real_kinds[i].max_exponent == 16384)
221 : : w = 15;
222 : 0 : else if (gfc_real_kinds[i].max_exponent == 1024)
223 : : w = 11;
224 : : else
225 : 0 : w = 8;
226 : :
227 : 0 : if (x->boz.rdx == 16)
228 : 0 : sp = hex2bin (gfc_real_kinds[i].mode_precision, x->boz.str);
229 : 0 : else if (x->boz.rdx == 8)
230 : 0 : sp = oct2bin (gfc_real_kinds[i].mode_precision, x->boz.str);
231 : : else
232 : 0 : sp = x->boz.str;
233 : :
234 : : /* Extract sign bit. */
235 : 0 : sgn = *sp != '0';
236 : :
237 : : /* Extract biased exponent. */
238 : 0 : memset (buf, 0, 114);
239 : 0 : strncpy (buf, ++sp, w);
240 : 0 : mpz_init (em);
241 : 0 : mpz_set_str (em, buf, 2);
242 : 0 : ie = mpz_get_si (em);
243 : :
244 : 0 : mpfr_init2 (x->value.real, t + 1);
245 : 0 : x->ts.type = BT_REAL;
246 : 0 : x->ts.kind = kind;
247 : :
248 : 0 : sp += w; /* Set to first digit in significand. */
249 : 0 : b = (1 << w) - 1;
250 : 0 : if ((i == 0 && ie == b) || (i == 1 && ie == b)
251 : 0 : || ((i == 2 || i == 3) && ie == b))
252 : : {
253 : 0 : bool zeros = true;
254 : 0 : if (i == 2) sp++;
255 : 0 : for (; *sp; sp++)
256 : : {
257 : 0 : if (*sp != '0')
258 : : {
259 : : zeros = false;
260 : : break;
261 : : }
262 : : }
263 : :
264 : 0 : if (zeros)
265 : 0 : mpfr_set_inf (x->value.real, 1);
266 : : else
267 : 0 : mpfr_set_nan (x->value.real);
268 : : }
269 : : else
270 : : {
271 : 0 : if (i == 2)
272 : 0 : strncpy (buf, sp, t + 1);
273 : : else
274 : : {
275 : : /* Significand with hidden bit. */
276 : 0 : buf[0] = '1';
277 : 0 : strncpy (&buf[1], sp, t);
278 : : }
279 : :
280 : : /* Convert to significand to integer. */
281 : 0 : mpz_set_str (em, buf, 2);
282 : 0 : ie -= ((1 << (w - 1)) - 1); /* Unbiased exponent. */
283 : 0 : mpfr_set_z_2exp (x->value.real, em, ie - t, GFC_RND_MODE);
284 : : }
285 : :
286 : 0 : if (sgn) mpfr_neg (x->value.real, x->value.real, GFC_RND_MODE);
287 : :
288 : 0 : mpz_clear (em);
289 : 0 : }
290 : :
291 : :
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. */
295 : :
296 : : bool
297 : 254 : gfc_boz2real (gfc_expr *x, int kind)
298 : : {
299 : 254 : extern int gfc_max_integer_kind;
300 : 254 : gfc_typespec ts;
301 : 254 : int len;
302 : 254 : char *buf, *str;
303 : :
304 : 254 : if (!is_boz_constant (x))
305 : 0 : return false;
306 : :
307 : : /* Determine the length of the required string. */
308 : 254 : len = 8 * kind;
309 : 254 : if (x->boz.rdx == 16) len /= 4;
310 : 254 : if (x->boz.rdx == 8) len = len / 3 + 1;
311 : 254 : buf = (char *) alloca (len + 1); /* +1 for NULL terminator. */
312 : :
313 : 254 : if (x->boz.len >= len) /* Truncate if necessary. */
314 : : {
315 : 172 : str = x->boz.str + (x->boz.len - len);
316 : 172 : strcpy(buf, str);
317 : : }
318 : : else /* Copy and pad. */
319 : : {
320 : 82 : memset (buf, 48, len);
321 : 82 : str = buf + (len - x->boz.len);
322 : 82 : strcpy (str, x->boz.str);
323 : : }
324 : :
325 : : /* Need to adjust leading bits in an octal string. */
326 : 254 : if (x->boz.rdx == 8)
327 : : {
328 : : /* Clear first bit. */
329 : 54 : if (kind == 4 || kind == 10 || kind == 16)
330 : : {
331 : 36 : if (buf[0] == '4')
332 : 0 : buf[0] = '0';
333 : 36 : else if (buf[0] == '5')
334 : 0 : buf[0] = '1';
335 : 36 : else if (buf[0] == '6')
336 : 0 : buf[0] = '2';
337 : 36 : else if (buf[0] == '7')
338 : 0 : buf[0] = '3';
339 : : }
340 : : /* Clear first two bits. */
341 : : else
342 : : {
343 : 18 : if (buf[0] == '2' || buf[0] == '4' || buf[0] == '6')
344 : 0 : buf[0] = '0';
345 : : else if (buf[0] == '3' || buf[0] == '5' || buf[0] == '7')
346 : 0 : buf[0] = '1';
347 : : }
348 : : }
349 : :
350 : : /* Reset BOZ string to the truncated or padded version. */
351 : 254 : free (x->boz.str);
352 : 254 : x->boz.len = len;
353 : 254 : x->boz.str = XCNEWVEC (char, len + 1);
354 : 254 : strncpy (x->boz.str, buf, len);
355 : :
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 : 254 : if (gfc_max_integer_kind < kind)
360 : : {
361 : 0 : bin2real (x, kind);
362 : : }
363 : : else
364 : : {
365 : : /* Convert to widest possible integer. */
366 : 254 : gfc_boz2int (x, gfc_max_integer_kind);
367 : 254 : ts.type = BT_REAL;
368 : 254 : ts.kind = kind;
369 : 254 : if (!gfc_convert_boz (x, &ts))
370 : : {
371 : 0 : gfc_error ("Failure in conversion of BOZ to REAL at %L", &x->where);
372 : 0 : return false;
373 : : }
374 : : }
375 : :
376 : : return true;
377 : : }
378 : :
379 : :
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
384 : : applied. */
385 : :
386 : : bool
387 : 2323 : gfc_boz2int (gfc_expr *x, int kind)
388 : : {
389 : 2323 : int i, len;
390 : 2323 : char *buf, *str;
391 : 2323 : mpz_t tmp1;
392 : :
393 : 2323 : if (!is_boz_constant (x))
394 : 0 : return false;
395 : :
396 : 2323 : i = gfc_validate_kind (BT_INTEGER, kind, false);
397 : 2323 : len = gfc_integer_kinds[i].bit_size;
398 : 2323 : if (x->boz.rdx == 16) len /= 4;
399 : 2323 : if (x->boz.rdx == 8) len = len / 3 + 1;
400 : 2323 : buf = (char *) alloca (len + 1); /* +1 for NULL terminator. */
401 : :
402 : 2323 : if (x->boz.len >= len) /* Truncate if necessary. */
403 : : {
404 : 802 : str = x->boz.str + (x->boz.len - len);
405 : 802 : strcpy(buf, str);
406 : : }
407 : : else /* Copy and pad. */
408 : : {
409 : 1521 : memset (buf, 48, len);
410 : 1521 : str = buf + (len - x->boz.len);
411 : 1521 : strcpy (str, x->boz.str);
412 : : }
413 : :
414 : : /* Need to adjust leading bits in an octal string. */
415 : 2323 : if (x->boz.rdx == 8)
416 : : {
417 : : /* Clear first bit. */
418 : 346 : if (kind == 1 || kind == 4 || kind == 16)
419 : : {
420 : 180 : if (buf[0] == '4')
421 : 0 : buf[0] = '0';
422 : 180 : else if (buf[0] == '5')
423 : 0 : buf[0] = '1';
424 : 180 : else if (buf[0] == '6')
425 : 1 : buf[0] = '2';
426 : 179 : else if (buf[0] == '7')
427 : 0 : buf[0] = '3';
428 : : }
429 : : /* Clear first two bits. */
430 : : else
431 : : {
432 : 166 : if (buf[0] == '2' || buf[0] == '4' || buf[0] == '6')
433 : 66 : buf[0] = '0';
434 : : else if (buf[0] == '3' || buf[0] == '5' || buf[0] == '7')
435 : 37 : buf[0] = '1';
436 : : }
437 : : }
438 : :
439 : : /* Convert as-if unsigned integer. */
440 : 2323 : mpz_init (tmp1);
441 : 2323 : mpz_set_str (tmp1, buf, x->boz.rdx);
442 : :
443 : : /* Check for wrap-around. */
444 : 2323 : if (mpz_cmp (tmp1, gfc_integer_kinds[i].huge) > 0)
445 : : {
446 : 103 : mpz_t tmp2;
447 : 103 : mpz_init (tmp2);
448 : 103 : mpz_add_ui (tmp2, gfc_integer_kinds[i].huge, 1);
449 : 103 : mpz_mod (tmp1, tmp1, tmp2);
450 : 103 : mpz_sub (tmp1, tmp1, tmp2);
451 : 103 : mpz_clear (tmp2);
452 : : }
453 : :
454 : : /* Clear boz info. */
455 : 2323 : x->boz.rdx = 0;
456 : 2323 : x->boz.len = 0;
457 : 2323 : free (x->boz.str);
458 : :
459 : 2323 : mpz_init (x->value.integer);
460 : 2323 : mpz_set (x->value.integer, tmp1);
461 : 2323 : x->ts.type = BT_INTEGER;
462 : 2323 : x->ts.kind = kind;
463 : 2323 : mpz_clear (tmp1);
464 : :
465 : 2323 : return true;
466 : : }
467 : :
468 : :
469 : : /* Make sure an expression is a scalar. */
470 : :
471 : : static bool
472 : 47851 : scalar_check (gfc_expr *e, int n)
473 : : {
474 : 47851 : if (e->rank == 0)
475 : : return true;
476 : :
477 : 33 : gfc_error ("%qs argument of %qs intrinsic at %L must be a scalar",
478 : 33 : gfc_current_intrinsic_arg[n]->name, gfc_current_intrinsic,
479 : : &e->where);
480 : :
481 : 33 : return false;
482 : : }
483 : :
484 : :
485 : : /* Check the type of an expression. */
486 : :
487 : : static bool
488 : 166543 : type_check (gfc_expr *e, int n, bt type)
489 : : {
490 : 166543 : if (e->ts.type == type)
491 : : return true;
492 : :
493 : 3150 : gfc_error ("%qs argument of %qs intrinsic at %L must be %s",
494 : 3150 : gfc_current_intrinsic_arg[n]->name, gfc_current_intrinsic,
495 : : &e->where, gfc_basic_typename (type));
496 : :
497 : 3150 : return false;
498 : : }
499 : :
500 : :
501 : : /* Check that the expression is a numeric type. */
502 : :
503 : : static bool
504 : 17342 : numeric_check (gfc_expr *e, int n)
505 : : {
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 : 17342 : if (e->symtree && e->symtree->n.sym->attr.subroutine)
509 : 1 : goto error;
510 : :
511 : 17341 : if (gfc_numeric_ts (&e->ts))
512 : : return true;
513 : :
514 : : /* If the expression has not got a type, check if its namespace can
515 : : offer a default type. */
516 : 1 : if ((e->expr_type == EXPR_VARIABLE || e->expr_type == EXPR_FUNCTION)
517 : 2 : && e->symtree->n.sym->ts.type == BT_UNKNOWN
518 : 0 : && gfc_set_default_type (e->symtree->n.sym, 0, e->symtree->n.sym->ns)
519 : 3 : && gfc_numeric_ts (&e->symtree->n.sym->ts))
520 : : {
521 : 0 : e->ts = e->symtree->n.sym->ts;
522 : 0 : return true;
523 : : }
524 : :
525 : 4 : error:
526 : :
527 : 4 : gfc_error ("%qs argument of %qs intrinsic at %L must have a numeric type",
528 : 4 : gfc_current_intrinsic_arg[n]->name, gfc_current_intrinsic,
529 : : &e->where);
530 : :
531 : 4 : return false;
532 : : }
533 : :
534 : :
535 : : /* Check that an expression is integer or real. */
536 : :
537 : : static bool
538 : 7634 : int_or_real_check (gfc_expr *e, int n)
539 : : {
540 : 7634 : if (e->ts.type != BT_INTEGER && e->ts.type != BT_REAL)
541 : : {
542 : 2 : gfc_error ("%qs argument of %qs intrinsic at %L must be INTEGER "
543 : 2 : "or REAL", gfc_current_intrinsic_arg[n]->name,
544 : : gfc_current_intrinsic, &e->where);
545 : 2 : return false;
546 : : }
547 : :
548 : : return true;
549 : : }
550 : :
551 : : /* Check that an expression is integer or real; allow character for
552 : : F2003 or later. */
553 : :
554 : : static bool
555 : 10533 : int_or_real_or_char_check_f2003 (gfc_expr *e, int n)
556 : : {
557 : 10533 : if (e->ts.type != BT_INTEGER && e->ts.type != BT_REAL)
558 : : {
559 : 1093 : if (e->ts.type == BT_CHARACTER)
560 : 1093 : return gfc_notify_std (GFC_STD_F2003, "Fortran 2003: Character for "
561 : : "%qs argument of %qs intrinsic at %L",
562 : 1093 : gfc_current_intrinsic_arg[n]->name,
563 : 1093 : gfc_current_intrinsic, &e->where);
564 : : else
565 : : {
566 : 0 : if (gfc_option.allow_std & GFC_STD_F2003)
567 : 0 : gfc_error ("%qs argument of %qs intrinsic at %L must be INTEGER "
568 : : "or REAL or CHARACTER",
569 : 0 : gfc_current_intrinsic_arg[n]->name,
570 : : gfc_current_intrinsic, &e->where);
571 : : else
572 : 0 : gfc_error ("%qs argument of %qs intrinsic at %L must be INTEGER "
573 : 0 : "or REAL", gfc_current_intrinsic_arg[n]->name,
574 : : gfc_current_intrinsic, &e->where);
575 : : }
576 : 0 : return false;
577 : : }
578 : :
579 : : return true;
580 : : }
581 : :
582 : : /* Check that an expression is an intrinsic type. */
583 : : static bool
584 : 1466 : intrinsic_type_check (gfc_expr *e, int n)
585 : : {
586 : 1466 : 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)
589 : : {
590 : 1 : gfc_error ("%qs argument of %qs intrinsic at %L must be of intrinsic type",
591 : 1 : gfc_current_intrinsic_arg[n]->name,
592 : : gfc_current_intrinsic, &e->where);
593 : 1 : return false;
594 : : }
595 : : return true;
596 : : }
597 : :
598 : : /* Check that an expression is real or complex. */
599 : :
600 : : static bool
601 : 3021 : real_or_complex_check (gfc_expr *e, int n)
602 : : {
603 : 3021 : if (e->ts.type != BT_REAL && e->ts.type != BT_COMPLEX)
604 : : {
605 : 0 : gfc_error ("%qs argument of %qs intrinsic at %L must be REAL "
606 : 0 : "or COMPLEX", gfc_current_intrinsic_arg[n]->name,
607 : : gfc_current_intrinsic, &e->where);
608 : 0 : return false;
609 : : }
610 : :
611 : : return true;
612 : : }
613 : :
614 : :
615 : : /* Check that an expression is INTEGER or PROCEDURE. */
616 : :
617 : : static bool
618 : 1 : int_or_proc_check (gfc_expr *e, int n)
619 : : {
620 : 1 : if (e->ts.type != BT_INTEGER && e->ts.type != BT_PROCEDURE)
621 : : {
622 : 0 : gfc_error ("%qs argument of %qs intrinsic at %L must be INTEGER "
623 : 0 : "or PROCEDURE", gfc_current_intrinsic_arg[n]->name,
624 : : gfc_current_intrinsic, &e->where);
625 : 0 : return false;
626 : : }
627 : :
628 : : return true;
629 : : }
630 : :
631 : :
632 : : /* Check that the expression is an optional constant integer
633 : : and that it specifies a valid kind for that type. */
634 : :
635 : : static bool
636 : 71318 : kind_check (gfc_expr *k, int n, bt type)
637 : : {
638 : 71318 : int kind;
639 : :
640 : 71318 : if (k == NULL)
641 : : return true;
642 : :
643 : 6438 : if (!type_check (k, n, BT_INTEGER))
644 : : return false;
645 : :
646 : 6438 : if (!scalar_check (k, n))
647 : : return false;
648 : :
649 : 6436 : if (!gfc_check_init_expr (k))
650 : : {
651 : 0 : gfc_error ("%qs argument of %qs intrinsic at %L must be a constant",
652 : 0 : gfc_current_intrinsic_arg[n]->name, gfc_current_intrinsic,
653 : : &k->where);
654 : 0 : return false;
655 : : }
656 : :
657 : 6436 : if (gfc_extract_int (k, &kind)
658 : 6436 : || gfc_validate_kind (type, kind, true) < 0)
659 : : {
660 : 1 : gfc_error ("Invalid kind for %s at %L", gfc_basic_typename (type),
661 : : &k->where);
662 : 1 : return false;
663 : : }
664 : :
665 : : return true;
666 : : }
667 : :
668 : :
669 : : /* Make sure the expression is a double precision real. */
670 : :
671 : : static bool
672 : 14978 : double_check (gfc_expr *d, int n)
673 : : {
674 : 14978 : if (!type_check (d, n, BT_REAL))
675 : : return false;
676 : :
677 : 11900 : if (d->ts.kind != gfc_default_double_kind)
678 : : {
679 : 6883 : gfc_error ("%qs argument of %qs intrinsic at %L must be double "
680 : 6883 : "precision", gfc_current_intrinsic_arg[n]->name,
681 : : gfc_current_intrinsic, &d->where);
682 : 6883 : return false;
683 : : }
684 : :
685 : : return true;
686 : : }
687 : :
688 : :
689 : : static bool
690 : 1208 : coarray_check (gfc_expr *e, int n)
691 : : {
692 : 66 : if (e->ts.type == BT_CLASS && gfc_expr_attr (e).class_ok
693 : 65 : && CLASS_DATA (e)->attr.codimension
694 : 1273 : && CLASS_DATA (e)->as->corank)
695 : : {
696 : 65 : gfc_add_class_array_ref (e);
697 : 65 : return true;
698 : : }
699 : :
700 : 1143 : if (!gfc_is_coarray (e))
701 : : {
702 : 9 : gfc_error ("Expected coarray variable as %qs argument to the %s "
703 : 9 : "intrinsic at %L", gfc_current_intrinsic_arg[n]->name,
704 : : gfc_current_intrinsic, &e->where);
705 : 9 : return false;
706 : : }
707 : :
708 : : return true;
709 : : }
710 : :
711 : :
712 : : /* Make sure the expression is a logical array. */
713 : :
714 : : static bool
715 : 31941 : logical_array_check (gfc_expr *array, int n)
716 : : {
717 : 31941 : if (array->ts.type != BT_LOGICAL || array->rank == 0)
718 : : {
719 : 0 : gfc_error ("%qs argument of %qs intrinsic at %L must be a logical "
720 : 0 : "array", gfc_current_intrinsic_arg[n]->name,
721 : : gfc_current_intrinsic, &array->where);
722 : 0 : return false;
723 : : }
724 : :
725 : : return true;
726 : : }
727 : :
728 : :
729 : : /* Make sure an expression is an array. */
730 : :
731 : : static bool
732 : 48029 : array_check (gfc_expr *e, int n)
733 : : {
734 : 48029 : if (e->rank != 0 && e->ts.type == BT_CLASS && gfc_expr_attr (e).class_ok
735 : 945 : && CLASS_DATA (e)->attr.dimension
736 : 48974 : && CLASS_DATA (e)->as->rank)
737 : : {
738 : 945 : gfc_add_class_array_ref (e);
739 : : }
740 : :
741 : 48029 : if (e->rank != 0 && e->ts.type != BT_PROCEDURE)
742 : : return true;
743 : :
744 : 11 : gfc_error ("%qs argument of %qs intrinsic at %L must be an array",
745 : 11 : gfc_current_intrinsic_arg[n]->name, gfc_current_intrinsic,
746 : : &e->where);
747 : :
748 : 11 : return false;
749 : : }
750 : :
751 : :
752 : : /* If expr is a constant, then check to ensure that it is greater than
753 : : of equal to zero. */
754 : :
755 : : static bool
756 : 10602 : nonnegative_check (const char *arg, gfc_expr *expr)
757 : : {
758 : 10602 : int i;
759 : :
760 : 10602 : if (expr->expr_type == EXPR_CONSTANT)
761 : : {
762 : 9780 : gfc_extract_int (expr, &i);
763 : 9780 : if (i < 0)
764 : : {
765 : 33 : gfc_error ("%qs at %L must be nonnegative", arg, &expr->where);
766 : 33 : return false;
767 : : }
768 : : }
769 : :
770 : : return true;
771 : : }
772 : :
773 : :
774 : : /* If expr is a constant, then check to ensure that it is greater than zero. */
775 : :
776 : : static bool
777 : 87 : positive_check (int n, gfc_expr *expr)
778 : : {
779 : 87 : int i;
780 : :
781 : 87 : if (expr->expr_type == EXPR_CONSTANT)
782 : : {
783 : 75 : gfc_extract_int (expr, &i);
784 : 75 : if (i <= 0)
785 : : {
786 : 8 : gfc_error ("%qs argument of %qs intrinsic at %L must be positive",
787 : 8 : gfc_current_intrinsic_arg[n]->name, gfc_current_intrinsic,
788 : : &expr->where);
789 : 8 : return false;
790 : : }
791 : : }
792 : :
793 : : return true;
794 : : }
795 : :
796 : :
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). */
799 : :
800 : : static bool
801 : 10739 : less_than_bitsize1 (const char *arg1, gfc_expr *expr1, const char *arg2,
802 : : gfc_expr *expr2, bool or_equal)
803 : : {
804 : 10739 : int i2, i3;
805 : :
806 : 10739 : if (expr2->expr_type == EXPR_CONSTANT)
807 : : {
808 : 9388 : gfc_extract_int (expr2, &i2);
809 : 9388 : i3 = gfc_validate_kind (BT_INTEGER, expr1->ts.kind, false);
810 : :
811 : : /* For ISHFT[C], check that |shift| <= bit_size(i). */
812 : 9388 : if (arg2 == NULL)
813 : : {
814 : 968 : if (i2 < 0)
815 : 270 : i2 = -i2;
816 : :
817 : 968 : if (i2 > gfc_integer_kinds[i3].bit_size)
818 : : {
819 : 4 : gfc_error ("The absolute value of SHIFT at %L must be less "
820 : : "than or equal to BIT_SIZE(%qs)",
821 : : &expr2->where, arg1);
822 : 4 : return false;
823 : : }
824 : : }
825 : :
826 : 9384 : if (or_equal)
827 : : {
828 : 9103 : if (i2 > gfc_integer_kinds[i3].bit_size)
829 : : {
830 : 7 : gfc_error ("%qs at %L must be less than "
831 : : "or equal to BIT_SIZE(%qs)",
832 : : arg2, &expr2->where, arg1);
833 : 7 : return false;
834 : : }
835 : : }
836 : : else
837 : : {
838 : 281 : if (i2 >= gfc_integer_kinds[i3].bit_size)
839 : : {
840 : 15 : gfc_error ("%qs at %L must be less than BIT_SIZE(%qs)",
841 : : arg2, &expr2->where, arg1);
842 : 15 : return false;
843 : : }
844 : : }
845 : : }
846 : :
847 : : return true;
848 : : }
849 : :
850 : :
851 : : /* If expr is constant, then check that the value is less than or equal
852 : : to the bit_size of the kind k. */
853 : :
854 : : static bool
855 : 922 : less_than_bitsizekind (const char *arg, gfc_expr *expr, int k)
856 : : {
857 : 922 : int i, val;
858 : :
859 : 922 : if (expr->expr_type != EXPR_CONSTANT)
860 : : return true;
861 : :
862 : 848 : i = gfc_validate_kind (BT_INTEGER, k, false);
863 : 848 : gfc_extract_int (expr, &val);
864 : :
865 : 848 : if (val > gfc_integer_kinds[i].bit_size)
866 : : {
867 : 4 : gfc_error ("%qs at %L must be less than or equal to the BIT_SIZE of "
868 : : "INTEGER(KIND=%d)", arg, &expr->where, k);
869 : 4 : return false;
870 : : }
871 : :
872 : : return true;
873 : : }
874 : :
875 : :
876 : : /* If expr2 and expr3 are constants, then check that the value is less than
877 : : or equal to bit_size(expr1). */
878 : :
879 : : static bool
880 : 394 : less_than_bitsize2 (const char *arg1, gfc_expr *expr1, const char *arg2,
881 : : gfc_expr *expr2, const char *arg3, gfc_expr *expr3)
882 : : {
883 : 394 : int i2, i3;
884 : :
885 : 394 : if (expr2->expr_type == EXPR_CONSTANT && expr3->expr_type == EXPR_CONSTANT)
886 : : {
887 : 286 : gfc_extract_int (expr2, &i2);
888 : 286 : gfc_extract_int (expr3, &i3);
889 : 286 : i2 += i3;
890 : 286 : i3 = gfc_validate_kind (BT_INTEGER, expr1->ts.kind, false);
891 : 286 : if (i2 > gfc_integer_kinds[i3].bit_size)
892 : : {
893 : 7 : gfc_error ("%<%s + %s%> at %L must be less than or equal "
894 : : "to BIT_SIZE(%qs)",
895 : : arg2, arg3, &expr2->where, arg1);
896 : 7 : return false;
897 : : }
898 : : }
899 : :
900 : : return true;
901 : : }
902 : :
903 : : /* Make sure two expressions have the same type. */
904 : :
905 : : static bool
906 : 9017 : same_type_check (gfc_expr *e, int n, gfc_expr *f, int m, bool assoc = false)
907 : : {
908 : 9017 : gfc_typespec *ets = &e->ts;
909 : 9017 : gfc_typespec *fts = &f->ts;
910 : :
911 : 9017 : if (assoc)
912 : : {
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
916 : : determined. */
917 : 1769 : if (e->ts.type == BT_PROCEDURE && e->symtree->n.sym)
918 : 92 : ets = &e->symtree->n.sym->ts;
919 : 1769 : if (f->ts.type == BT_PROCEDURE && f->symtree->n.sym)
920 : 91 : fts = &f->symtree->n.sym->ts;
921 : : }
922 : :
923 : 9017 : if (gfc_compare_types (ets, fts))
924 : : return true;
925 : :
926 : 24 : gfc_error ("%qs argument of %qs intrinsic at %L must be the same type "
927 : 24 : "and kind as %qs", gfc_current_intrinsic_arg[m]->name,
928 : : gfc_current_intrinsic, &f->where,
929 : 24 : gfc_current_intrinsic_arg[n]->name);
930 : :
931 : 24 : return false;
932 : : }
933 : :
934 : :
935 : : /* Make sure that an expression has a certain (nonzero) rank. */
936 : :
937 : : static bool
938 : 10096 : rank_check (gfc_expr *e, int n, int rank)
939 : : {
940 : 10096 : if (e->rank == rank)
941 : : return true;
942 : :
943 : 3 : gfc_error ("%qs argument of %qs intrinsic at %L must be of rank %d",
944 : 3 : gfc_current_intrinsic_arg[n]->name, gfc_current_intrinsic,
945 : : &e->where, rank);
946 : :
947 : 3 : return false;
948 : : }
949 : :
950 : :
951 : : /* Make sure a variable expression is not an optional dummy argument. */
952 : :
953 : : static bool
954 : 19564 : nonoptional_check (gfc_expr *e, int n)
955 : : {
956 : 19564 : if (e->expr_type == EXPR_VARIABLE && e->symtree->n.sym->attr.optional)
957 : : {
958 : 2 : gfc_error ("%qs argument of %qs intrinsic at %L must not be OPTIONAL",
959 : 2 : gfc_current_intrinsic_arg[n]->name, gfc_current_intrinsic,
960 : : &e->where);
961 : : }
962 : :
963 : : /* TODO: Recursive check on nonoptional variables? */
964 : :
965 : 19564 : return true;
966 : : }
967 : :
968 : :
969 : : /* Check for ALLOCATABLE attribute. */
970 : :
971 : : static bool
972 : 6919 : allocatable_check (gfc_expr *e, int n)
973 : : {
974 : 6919 : symbol_attribute attr;
975 : :
976 : 6919 : attr = gfc_variable_attr (e, NULL);
977 : 6919 : if (!attr.allocatable
978 : 6909 : || (attr.associate_var && !attr.select_rank_temporary))
979 : : {
980 : 11 : gfc_error ("%qs argument of %qs intrinsic at %L must be ALLOCATABLE",
981 : 11 : gfc_current_intrinsic_arg[n]->name, gfc_current_intrinsic,
982 : : &e->where);
983 : 11 : return false;
984 : : }
985 : :
986 : : return true;
987 : : }
988 : :
989 : :
990 : : /* Check that an expression has a particular kind. */
991 : :
992 : : static bool
993 : 2783 : kind_value_check (gfc_expr *e, int n, int k)
994 : : {
995 : 2783 : if (e->ts.kind == k)
996 : : return true;
997 : :
998 : 140 : gfc_error ("%qs argument of %qs intrinsic at %L must be of kind %d",
999 : 140 : gfc_current_intrinsic_arg[n]->name, gfc_current_intrinsic,
1000 : : &e->where, k);
1001 : :
1002 : 140 : return false;
1003 : : }
1004 : :
1005 : :
1006 : : /* Make sure an expression is a variable. */
1007 : :
1008 : : static bool
1009 : 18326 : variable_check (gfc_expr *e, int n, bool allow_proc)
1010 : : {
1011 : 18326 : if (e->expr_type == EXPR_VARIABLE
1012 : 18309 : && e->symtree->n.sym->attr.intent == INTENT_IN
1013 : 1208 : && (gfc_current_intrinsic_arg[n]->intent == INTENT_OUT
1014 : 1197 : || gfc_current_intrinsic_arg[n]->intent == INTENT_INOUT)
1015 : 18353 : && !gfc_check_vardef_context (e, false, true, false, NULL))
1016 : : {
1017 : 6 : gfc_error ("%qs argument of %qs intrinsic at %L cannot be INTENT(IN)",
1018 : 6 : gfc_current_intrinsic_arg[n]->name,
1019 : : gfc_current_intrinsic, &e->where);
1020 : 6 : return false;
1021 : : }
1022 : :
1023 : 18320 : if (e->expr_type == EXPR_VARIABLE
1024 : 18303 : && e->symtree->n.sym->attr.flavor != FL_PARAMETER
1025 : 18303 : && (allow_proc || !e->symtree->n.sym->attr.function))
1026 : : return true;
1027 : :
1028 : 61 : if (e->expr_type == EXPR_VARIABLE && e->symtree->n.sym->attr.function
1029 : 44 : && e->symtree->n.sym == e->symtree->n.sym->result)
1030 : : {
1031 : 44 : gfc_namespace *ns;
1032 : 55 : for (ns = gfc_current_ns; ns; ns = ns->parent)
1033 : 54 : if (ns->proc_name == e->symtree->n.sym)
1034 : : return true;
1035 : : }
1036 : :
1037 : : /* F2018:R902: function reference having a data pointer result. */
1038 : 18 : if (e->expr_type == EXPR_FUNCTION
1039 : 1 : && e->symtree->n.sym->attr.flavor == FL_PROCEDURE
1040 : : && e->symtree->n.sym->attr.function
1041 : 1 : && e->symtree->n.sym->attr.pointer)
1042 : : return true;
1043 : :
1044 : 17 : gfc_error ("%qs argument of %qs intrinsic at %L must be a variable",
1045 : 17 : gfc_current_intrinsic_arg[n]->name, gfc_current_intrinsic, &e->where);
1046 : :
1047 : 17 : return false;
1048 : : }
1049 : :
1050 : :
1051 : : /* Check the common DIM parameter for correctness. */
1052 : :
1053 : : static bool
1054 : 73541 : dim_check (gfc_expr *dim, int n, bool optional)
1055 : : {
1056 : 73541 : if (dim == NULL)
1057 : : return true;
1058 : :
1059 : 23773 : if (!type_check (dim, n, BT_INTEGER))
1060 : : return false;
1061 : :
1062 : 23772 : if (!scalar_check (dim, n))
1063 : : return false;
1064 : :
1065 : 23769 : if (!optional && !nonoptional_check (dim, n))
1066 : : return false;
1067 : :
1068 : : return true;
1069 : : }
1070 : :
1071 : :
1072 : : /* If a coarray DIM parameter is a constant, make sure that it is greater than
1073 : : zero and less than or equal to the corank of the given array. */
1074 : :
1075 : : static bool
1076 : 666 : dim_corank_check (gfc_expr *dim, gfc_expr *array)
1077 : : {
1078 : 666 : int corank;
1079 : :
1080 : 666 : gcc_assert (array->expr_type == EXPR_VARIABLE);
1081 : :
1082 : 666 : if (dim->expr_type != EXPR_CONSTANT)
1083 : : return true;
1084 : :
1085 : 514 : if (array->ts.type == BT_CLASS)
1086 : : return true;
1087 : :
1088 : 504 : corank = gfc_get_corank (array);
1089 : :
1090 : 504 : if (mpz_cmp_ui (dim->value.integer, 1) < 0
1091 : 504 : || mpz_cmp_ui (dim->value.integer, corank) > 0)
1092 : : {
1093 : 1 : gfc_error ("%<dim%> argument of %qs intrinsic at %L is not a valid "
1094 : : "codimension index", gfc_current_intrinsic, &dim->where);
1095 : :
1096 : 1 : return false;
1097 : : }
1098 : :
1099 : : return true;
1100 : : }
1101 : :
1102 : :
1103 : : /* If a DIM parameter is a constant, make sure that it is greater than
1104 : : zero and less than or equal to the rank of the given array. If
1105 : : allow_assumed is zero then dim must be less than the rank of the array
1106 : : for assumed size arrays. */
1107 : :
1108 : : static bool
1109 : 72202 : dim_rank_check (gfc_expr *dim, gfc_expr *array, int allow_assumed)
1110 : : {
1111 : 72202 : gfc_array_ref *ar;
1112 : 72202 : int rank;
1113 : :
1114 : 72202 : if (dim == NULL)
1115 : : return true;
1116 : :
1117 : 22434 : if (dim->expr_type != EXPR_CONSTANT)
1118 : : return true;
1119 : :
1120 : 21043 : if (array->expr_type == EXPR_FUNCTION && array->value.function.isym
1121 : 639 : && array->value.function.isym->id == GFC_ISYM_SPREAD)
1122 : 60 : rank = array->rank + 1;
1123 : : else
1124 : 20983 : rank = array->rank;
1125 : :
1126 : : /* Assumed-rank array. */
1127 : 21043 : if (rank == -1)
1128 : 1164 : rank = GFC_MAX_DIMENSIONS;
1129 : :
1130 : 21043 : if (array->expr_type == EXPR_VARIABLE)
1131 : : {
1132 : 19856 : ar = gfc_find_array_ref (array, true);
1133 : 19856 : if (!ar)
1134 : : return false;
1135 : 19855 : if (ar->as->type == AS_ASSUMED_SIZE
1136 : 430 : && !allow_assumed
1137 : 190 : && ar->type != AR_ELEMENT
1138 : 190 : && ar->type != AR_SECTION)
1139 : 184 : rank--;
1140 : : }
1141 : :
1142 : 21042 : if (mpz_cmp_ui (dim->value.integer, 1) < 0
1143 : 21040 : || mpz_cmp_ui (dim->value.integer, rank) > 0)
1144 : : {
1145 : 11 : gfc_error ("%<dim%> argument of %qs intrinsic at %L is not a valid "
1146 : : "dimension index", gfc_current_intrinsic, &dim->where);
1147 : :
1148 : 11 : return false;
1149 : : }
1150 : :
1151 : : return true;
1152 : : }
1153 : :
1154 : :
1155 : : /* Compare the size of a along dimension ai with the size of b along
1156 : : dimension bi, returning 0 if they are known not to be identical,
1157 : : and 1 if they are identical, or if this cannot be determined. */
1158 : :
1159 : : static bool
1160 : 2547 : identical_dimen_shape (gfc_expr *a, int ai, gfc_expr *b, int bi)
1161 : : {
1162 : 2547 : mpz_t a_size, b_size;
1163 : 2547 : bool ret;
1164 : :
1165 : 2547 : gcc_assert (a->rank > ai);
1166 : 2547 : gcc_assert (b->rank > bi);
1167 : :
1168 : 2547 : ret = true;
1169 : :
1170 : 2547 : if (gfc_array_dimen_size (a, ai, &a_size))
1171 : : {
1172 : 2042 : if (gfc_array_dimen_size (b, bi, &b_size))
1173 : : {
1174 : 1963 : if (mpz_cmp (a_size, b_size) != 0)
1175 : 10 : ret = false;
1176 : :
1177 : 1963 : mpz_clear (b_size);
1178 : : }
1179 : 2042 : mpz_clear (a_size);
1180 : : }
1181 : 2547 : return ret;
1182 : : }
1183 : :
1184 : : /* Calculate the length of a character variable, including substrings.
1185 : : Strip away parentheses if necessary. Return -1 if no length could
1186 : : be determined. */
1187 : :
1188 : : static long
1189 : 4276 : gfc_var_strlen (const gfc_expr *a)
1190 : : {
1191 : 4276 : gfc_ref *ra;
1192 : :
1193 : 4276 : while (a->expr_type == EXPR_OP && a->value.op.op == INTRINSIC_PARENTHESES)
1194 : 0 : a = a->value.op.op1;
1195 : :
1196 : 6070 : for (ra = a->ref; ra != NULL && ra->type != REF_SUBSTRING; ra = ra->next)
1197 : : ;
1198 : :
1199 : 4276 : if (ra)
1200 : : {
1201 : 207 : long start_a, end_a;
1202 : :
1203 : 207 : if (!ra->u.ss.end)
1204 : : return -1;
1205 : :
1206 : 206 : if ((!ra->u.ss.start || ra->u.ss.start->expr_type == EXPR_CONSTANT)
1207 : 197 : && ra->u.ss.end->expr_type == EXPR_CONSTANT)
1208 : : {
1209 : 191 : start_a = ra->u.ss.start ? mpz_get_si (ra->u.ss.start->value.integer)
1210 : : : 1;
1211 : 191 : end_a = mpz_get_si (ra->u.ss.end->value.integer);
1212 : 191 : return (end_a < start_a) ? 0 : end_a - start_a + 1;
1213 : : }
1214 : 15 : else if (ra->u.ss.start
1215 : 15 : && gfc_dep_compare_expr (ra->u.ss.start, ra->u.ss.end) == 0)
1216 : : return 1;
1217 : : else
1218 : 13 : return -1;
1219 : : }
1220 : :
1221 : 4069 : if (a->ts.u.cl && a->ts.u.cl->length
1222 : 2445 : && a->ts.u.cl->length->expr_type == EXPR_CONSTANT)
1223 : 2364 : return mpz_get_si (a->ts.u.cl->length->value.integer);
1224 : 1705 : else if (a->expr_type == EXPR_CONSTANT
1225 : 373 : && (a->ts.u.cl == NULL || a->ts.u.cl->length == NULL))
1226 : 373 : return a->value.character.length;
1227 : : else
1228 : : return -1;
1229 : :
1230 : : }
1231 : :
1232 : : /* Check whether two character expressions have the same length;
1233 : : returns true if they have or if the length cannot be determined,
1234 : : otherwise return false and raise a gfc_error. */
1235 : :
1236 : : bool
1237 : 1747 : gfc_check_same_strlen (const gfc_expr *a, const gfc_expr *b, const char *name)
1238 : : {
1239 : 1747 : long len_a, len_b;
1240 : :
1241 : 1747 : len_a = gfc_var_strlen(a);
1242 : 1747 : len_b = gfc_var_strlen(b);
1243 : :
1244 : 1747 : if (len_a == -1 || len_b == -1 || len_a == len_b)
1245 : : return true;
1246 : : else
1247 : : {
1248 : 23 : gfc_error ("Unequal character lengths (%ld/%ld) in %s at %L",
1249 : : len_a, len_b, name, &a->where);
1250 : 23 : return false;
1251 : : }
1252 : : }
1253 : :
1254 : : /* Check size of an array argument against a required size.
1255 : : Returns true if the requirement is satisfied or if the size cannot be
1256 : : determined, otherwise return false and raise a gfc_error */
1257 : :
1258 : : static bool
1259 : 110 : array_size_check (gfc_expr *a, int n, long size_min)
1260 : : {
1261 : 110 : bool ok = true;
1262 : 110 : mpz_t size;
1263 : :
1264 : 110 : if (gfc_array_size (a, &size))
1265 : : {
1266 : 110 : HOST_WIDE_INT sz = gfc_mpz_get_hwi (size);
1267 : 110 : if (size_min >= 0 && sz < size_min)
1268 : : {
1269 : 1 : gfc_error ("Size of %qs argument of %qs intrinsic at %L "
1270 : : "too small (%wd/%ld)",
1271 : 1 : gfc_current_intrinsic_arg[n]->name,
1272 : : gfc_current_intrinsic, &a->where, sz, size_min);
1273 : 1 : ok = false;
1274 : : }
1275 : 110 : mpz_clear (size);
1276 : : }
1277 : :
1278 : 110 : return ok;
1279 : : }
1280 : :
1281 : :
1282 : : /***** Check functions *****/
1283 : :
1284 : : /* Check subroutine suitable for intrinsics taking a real argument and
1285 : : a kind argument for the result. */
1286 : :
1287 : : static bool
1288 : 645 : check_a_kind (gfc_expr *a, gfc_expr *kind, bt type)
1289 : : {
1290 : 645 : if (!type_check (a, 0, BT_REAL))
1291 : : return false;
1292 : 645 : if (!kind_check (kind, 1, type))
1293 : : return false;
1294 : :
1295 : : return true;
1296 : : }
1297 : :
1298 : :
1299 : : /* Check subroutine suitable for ceiling, floor and nint. */
1300 : :
1301 : : bool
1302 : 383 : gfc_check_a_ikind (gfc_expr *a, gfc_expr *kind)
1303 : : {
1304 : 383 : return check_a_kind (a, kind, BT_INTEGER);
1305 : : }
1306 : :
1307 : :
1308 : : /* Check subroutine suitable for aint, anint. */
1309 : :
1310 : : bool
1311 : 262 : gfc_check_a_xkind (gfc_expr *a, gfc_expr *kind)
1312 : : {
1313 : 262 : return check_a_kind (a, kind, BT_REAL);
1314 : : }
1315 : :
1316 : :
1317 : : bool
1318 : 4419 : gfc_check_abs (gfc_expr *a)
1319 : : {
1320 : 4419 : if (!numeric_check (a, 0))
1321 : : return false;
1322 : :
1323 : : return true;
1324 : : }
1325 : :
1326 : :
1327 : : bool
1328 : 6806 : gfc_check_achar (gfc_expr *a, gfc_expr *kind)
1329 : : {
1330 : 6806 : if (a->ts.type == BT_BOZ)
1331 : : {
1332 : 0 : if (gfc_invalid_boz (G_("BOZ literal constant at %L cannot appear in "
1333 : : "ACHAR intrinsic subprogram"), &a->where))
1334 : : return false;
1335 : :
1336 : 0 : if (!gfc_boz2int (a, gfc_default_integer_kind))
1337 : : return false;
1338 : : }
1339 : :
1340 : 6806 : if (!type_check (a, 0, BT_INTEGER))
1341 : : return false;
1342 : :
1343 : 6806 : if (!kind_check (kind, 1, BT_CHARACTER))
1344 : : return false;
1345 : :
1346 : : return true;
1347 : : }
1348 : :
1349 : :
1350 : : bool
1351 : 292 : gfc_check_access_func (gfc_expr *name, gfc_expr *mode)
1352 : : {
1353 : 292 : if (!type_check (name, 0, BT_CHARACTER)
1354 : 292 : || !scalar_check (name, 0))
1355 : 0 : return false;
1356 : 292 : if (!kind_value_check (name, 0, gfc_default_character_kind))
1357 : : return false;
1358 : :
1359 : 290 : if (!type_check (mode, 1, BT_CHARACTER)
1360 : 290 : || !scalar_check (mode, 1))
1361 : 0 : return false;
1362 : 290 : if (!kind_value_check (mode, 1, gfc_default_character_kind))
1363 : : return false;
1364 : :
1365 : : return true;
1366 : : }
1367 : :
1368 : :
1369 : : bool
1370 : 31593 : gfc_check_all_any (gfc_expr *mask, gfc_expr *dim)
1371 : : {
1372 : 31593 : if (!logical_array_check (mask, 0))
1373 : : return false;
1374 : :
1375 : 31593 : if (!dim_check (dim, 1, false))
1376 : : return false;
1377 : :
1378 : 31593 : if (!dim_rank_check (dim, mask, 0))
1379 : : return false;
1380 : :
1381 : : return true;
1382 : : }
1383 : :
1384 : :
1385 : : /* Limited checking for ALLOCATED intrinsic. Additional checking
1386 : : is performed in intrinsic.cc(sort_actual), because ALLOCATED
1387 : : has two mutually exclusive non-optional arguments. */
1388 : :
1389 : : bool
1390 : 6432 : gfc_check_allocated (gfc_expr *array)
1391 : : {
1392 : : /* Tests on allocated components of coarrays need to detour the check to
1393 : : argument of the _caf_get. */
1394 : 6432 : if (flag_coarray == GFC_FCOARRAY_LIB && array->expr_type == EXPR_FUNCTION
1395 : 66 : && array->value.function.isym
1396 : 66 : && array->value.function.isym->id == GFC_ISYM_CAF_GET)
1397 : : {
1398 : 66 : array = array->value.function.actual->expr;
1399 : 66 : if (!array->ref)
1400 : : return false;
1401 : : }
1402 : :
1403 : 6432 : if (!variable_check (array, 0, false))
1404 : : return false;
1405 : 6431 : if (!allocatable_check (array, 0))
1406 : : return false;
1407 : :
1408 : : return true;
1409 : : }
1410 : :
1411 : :
1412 : : /* Common check function where the first argument must be real or
1413 : : integer and the second argument must be the same as the first. */
1414 : :
1415 : : bool
1416 : 1547 : gfc_check_a_p (gfc_expr *a, gfc_expr *p)
1417 : : {
1418 : 1547 : if (!int_or_real_check (a, 0))
1419 : : return false;
1420 : :
1421 : 1547 : if (a->ts.type != p->ts.type)
1422 : : {
1423 : 0 : gfc_error ("%qs and %qs arguments of %qs intrinsic at %L must "
1424 : 0 : "have the same type", gfc_current_intrinsic_arg[0]->name,
1425 : 0 : gfc_current_intrinsic_arg[1]->name, gfc_current_intrinsic,
1426 : : &p->where);
1427 : 0 : return false;
1428 : : }
1429 : :
1430 : 1547 : if (a->ts.kind != p->ts.kind)
1431 : : {
1432 : 85 : if (!gfc_notify_std (GFC_STD_GNU, "Different type kinds at %L",
1433 : : &p->where))
1434 : : return false;
1435 : : }
1436 : :
1437 : : return true;
1438 : : }
1439 : :
1440 : :
1441 : : bool
1442 : 1382 : gfc_check_x_yd (gfc_expr *x, gfc_expr *y)
1443 : : {
1444 : 1382 : if (!double_check (x, 0) || !double_check (y, 1))
1445 : 1228 : return false;
1446 : :
1447 : : return true;
1448 : : }
1449 : :
1450 : : bool
1451 : 37414 : gfc_invalid_null_arg (gfc_expr *x)
1452 : : {
1453 : 37414 : if (x->expr_type == EXPR_NULL)
1454 : : {
1455 : 23 : gfc_error ("NULL at %L is not permitted as actual argument "
1456 : : "to %qs intrinsic function", &x->where,
1457 : : gfc_current_intrinsic);
1458 : 23 : return true;
1459 : : }
1460 : : return false;
1461 : : }
1462 : :
1463 : : bool
1464 : 6232 : gfc_check_associated (gfc_expr *pointer, gfc_expr *target)
1465 : : {
1466 : 6232 : symbol_attribute attr1, attr2;
1467 : 6232 : int i;
1468 : 6232 : bool t;
1469 : :
1470 : 6232 : if (gfc_invalid_null_arg (pointer))
1471 : : return false;
1472 : :
1473 : 6231 : attr1 = gfc_expr_attr (pointer);
1474 : :
1475 : 6231 : if (!attr1.pointer && !attr1.proc_pointer)
1476 : : {
1477 : 1 : gfc_error ("%qs argument of %qs intrinsic at %L must be a POINTER",
1478 : 1 : gfc_current_intrinsic_arg[0]->name, gfc_current_intrinsic,
1479 : : &pointer->where);
1480 : 1 : return false;
1481 : : }
1482 : :
1483 : : /* F2008, C1242. */
1484 : 6230 : if (attr1.pointer && gfc_is_coindexed (pointer))
1485 : : {
1486 : 1 : gfc_error ("%qs argument of %qs intrinsic at %L shall not be "
1487 : 1 : "coindexed", gfc_current_intrinsic_arg[0]->name,
1488 : : gfc_current_intrinsic, &pointer->where);
1489 : 1 : return false;
1490 : : }
1491 : :
1492 : : /* Target argument is optional. */
1493 : 6229 : if (target == NULL)
1494 : : return true;
1495 : :
1496 : 1772 : if (gfc_invalid_null_arg (target))
1497 : : return false;
1498 : :
1499 : 1771 : if (target->expr_type == EXPR_VARIABLE || target->expr_type == EXPR_FUNCTION)
1500 : 1770 : attr2 = gfc_expr_attr (target);
1501 : : else
1502 : : {
1503 : 1 : gfc_error ("%qs argument of %qs intrinsic at %L must be a pointer "
1504 : : "or target VARIABLE or FUNCTION",
1505 : 1 : gfc_current_intrinsic_arg[1]->name, gfc_current_intrinsic,
1506 : : &target->where);
1507 : 1 : return false;
1508 : : }
1509 : :
1510 : 1770 : if (attr1.pointer && !attr2.pointer && !attr2.target)
1511 : : {
1512 : 0 : gfc_error ("%qs argument of %qs intrinsic at %L must be a POINTER "
1513 : 0 : "or a TARGET", gfc_current_intrinsic_arg[1]->name,
1514 : : gfc_current_intrinsic, &target->where);
1515 : 0 : return false;
1516 : : }
1517 : :
1518 : : /* F2008, C1242. */
1519 : 1770 : if (attr1.pointer && gfc_is_coindexed (target))
1520 : : {
1521 : 1 : gfc_error ("%qs argument of %qs intrinsic at %L shall not be "
1522 : 1 : "coindexed", gfc_current_intrinsic_arg[1]->name,
1523 : : gfc_current_intrinsic, &target->where);
1524 : 1 : return false;
1525 : : }
1526 : :
1527 : 1769 : t = true;
1528 : 1769 : if (!same_type_check (pointer, 0, target, 1, true))
1529 : : t = false;
1530 : : /* F2018 C838 explicitly allows an assumed-rank variable as the first
1531 : : argument of intrinsic inquiry functions. */
1532 : 1769 : if (pointer->rank != -1 && !rank_check (target, 0, pointer->rank))
1533 : : t = false;
1534 : 1769 : if (target->rank > 0 && target->ref)
1535 : : {
1536 : 2103 : for (i = 0; i < target->rank; i++)
1537 : 1191 : if (target->ref->u.ar.dimen_type[i] == DIMEN_VECTOR)
1538 : : {
1539 : 0 : gfc_error ("Array section with a vector subscript at %L shall not "
1540 : : "be the target of a pointer",
1541 : : &target->where);
1542 : 0 : t = false;
1543 : 0 : break;
1544 : : }
1545 : : }
1546 : : return t;
1547 : : }
1548 : :
1549 : :
1550 : : bool
1551 : 74 : gfc_check_atan_2 (gfc_expr *y, gfc_expr *x)
1552 : : {
1553 : : /* gfc_notify_std would be a waste of time as the return value
1554 : : is seemingly used only for the generic resolution. The error
1555 : : will be: Too many arguments. */
1556 : 74 : if ((gfc_option.allow_std & GFC_STD_F2008) == 0)
1557 : : return false;
1558 : :
1559 : 72 : return gfc_check_atan2 (y, x);
1560 : : }
1561 : :
1562 : :
1563 : : bool
1564 : 413 : gfc_check_atan2 (gfc_expr *y, gfc_expr *x)
1565 : : {
1566 : 413 : if (!type_check (y, 0, BT_REAL))
1567 : : return false;
1568 : 409 : if (!same_type_check (y, 0, x, 1))
1569 : : return false;
1570 : :
1571 : : return true;
1572 : : }
1573 : :
1574 : :
1575 : : static bool
1576 : 275 : gfc_check_atomic (gfc_expr *atom, int atom_no, gfc_expr *value, int val_no,
1577 : : gfc_expr *stat, int stat_no)
1578 : : {
1579 : 275 : if (!scalar_check (atom, atom_no) || !scalar_check (value, val_no))
1580 : 1 : return false;
1581 : :
1582 : 274 : if (!(atom->ts.type == BT_INTEGER && atom->ts.kind == gfc_atomic_int_kind)
1583 : 50 : && !(atom->ts.type == BT_LOGICAL
1584 : 47 : && atom->ts.kind == gfc_atomic_logical_kind))
1585 : : {
1586 : 7 : gfc_error ("ATOM argument at %L to intrinsic function %s shall be an "
1587 : : "integer of ATOMIC_INT_KIND or a logical of "
1588 : : "ATOMIC_LOGICAL_KIND", &atom->where, gfc_current_intrinsic);
1589 : 7 : return false;
1590 : : }
1591 : :
1592 : 267 : if (!gfc_is_coarray (atom) && !gfc_is_coindexed (atom))
1593 : : {
1594 : 14 : gfc_error ("ATOM argument at %L of the %s intrinsic function shall be a "
1595 : : "coarray or coindexed", &atom->where, gfc_current_intrinsic);
1596 : 14 : return false;
1597 : : }
1598 : :
1599 : 253 : if (atom->ts.type != value->ts.type)
1600 : : {
1601 : 13 : gfc_error ("%qs argument of %qs intrinsic at %L shall have the same "
1602 : 13 : "type as %qs at %L", gfc_current_intrinsic_arg[val_no]->name,
1603 : : gfc_current_intrinsic, &value->where,
1604 : 13 : gfc_current_intrinsic_arg[atom_no]->name, &atom->where);
1605 : 13 : return false;
1606 : : }
1607 : :
1608 : 240 : if (stat != NULL)
1609 : : {
1610 : 211 : if (!type_check (stat, stat_no, BT_INTEGER))
1611 : : return false;
1612 : 211 : if (!scalar_check (stat, stat_no))
1613 : : return false;
1614 : 211 : if (!variable_check (stat, stat_no, false))
1615 : : return false;
1616 : 211 : if (!kind_value_check (stat, stat_no, gfc_default_integer_kind))
1617 : : return false;
1618 : :
1619 : 200 : if (!gfc_notify_std (GFC_STD_F2018, "STAT= argument to %s at %L",
1620 : : gfc_current_intrinsic, &stat->where))
1621 : : return false;
1622 : : }
1623 : :
1624 : : return true;
1625 : : }
1626 : :
1627 : :
1628 : : bool
1629 : 73 : gfc_check_atomic_def (gfc_expr *atom, gfc_expr *value, gfc_expr *stat)
1630 : : {
1631 : 73 : if (atom->expr_type == EXPR_FUNCTION
1632 : 15 : && atom->value.function.isym
1633 : 15 : && atom->value.function.isym->id == GFC_ISYM_CAF_GET)
1634 : 15 : atom = atom->value.function.actual->expr;
1635 : :
1636 : 73 : if (!gfc_check_vardef_context (atom, false, false, false, NULL))
1637 : : {
1638 : 0 : gfc_error ("ATOM argument of the %s intrinsic function at %L shall be "
1639 : : "definable", gfc_current_intrinsic, &atom->where);
1640 : 0 : return false;
1641 : : }
1642 : :
1643 : 73 : return gfc_check_atomic (atom, 0, value, 1, stat, 2);
1644 : : }
1645 : :
1646 : :
1647 : : bool
1648 : 51 : gfc_check_atomic_op (gfc_expr *atom, gfc_expr *value, gfc_expr *stat)
1649 : : {
1650 : 51 : if (atom->ts.type != BT_INTEGER || atom->ts.kind != gfc_atomic_int_kind)
1651 : : {
1652 : 4 : gfc_error ("ATOM argument at %L to intrinsic function %s shall be an "
1653 : : "integer of ATOMIC_INT_KIND", &atom->where,
1654 : : gfc_current_intrinsic);
1655 : 4 : return false;
1656 : : }
1657 : :
1658 : 47 : return gfc_check_atomic_def (atom, value, stat);
1659 : : }
1660 : :
1661 : :
1662 : : bool
1663 : 130 : gfc_check_atomic_ref (gfc_expr *value, gfc_expr *atom, gfc_expr *stat)
1664 : : {
1665 : 130 : if (atom->expr_type == EXPR_FUNCTION
1666 : 52 : && atom->value.function.isym
1667 : 52 : && atom->value.function.isym->id == GFC_ISYM_CAF_GET)
1668 : 52 : atom = atom->value.function.actual->expr;
1669 : :
1670 : 130 : if (!gfc_check_vardef_context (value, false, false, false, NULL))
1671 : : {
1672 : 1 : gfc_error ("VALUE argument of the %s intrinsic function at %L shall be "
1673 : : "definable", gfc_current_intrinsic, &value->where);
1674 : 1 : return false;
1675 : : }
1676 : :
1677 : 129 : return gfc_check_atomic (atom, 1, value, 0, stat, 2);
1678 : : }
1679 : :
1680 : :
1681 : : bool
1682 : 39 : gfc_check_image_status (gfc_expr *image, gfc_expr *team)
1683 : : {
1684 : : /* IMAGE has to be a positive, scalar integer. */
1685 : 76 : if (!type_check (image, 0, BT_INTEGER) || !scalar_check (image, 0)
1686 : 74 : || !positive_check (0, image))
1687 : 8 : return false;
1688 : :
1689 : 31 : if (team)
1690 : : {
1691 : 2 : gfc_error ("%qs argument of %qs intrinsic at %L not yet supported",
1692 : 2 : gfc_current_intrinsic_arg[1]->name, gfc_current_intrinsic,
1693 : : &team->where);
1694 : 2 : return false;
1695 : : }
1696 : : return true;
1697 : : }
1698 : :
1699 : :
1700 : : bool
1701 : 80 : gfc_check_failed_or_stopped_images (gfc_expr *team, gfc_expr *kind)
1702 : : {
1703 : 80 : if (team)
1704 : : {
1705 : 4 : gfc_error ("%qs argument of %qs intrinsic at %L not yet supported",
1706 : 4 : gfc_current_intrinsic_arg[0]->name, gfc_current_intrinsic,
1707 : : &team->where);
1708 : 4 : return false;
1709 : : }
1710 : :
1711 : 76 : if (kind)
1712 : : {
1713 : 56 : int k;
1714 : :
1715 : 108 : if (!type_check (kind, 1, BT_INTEGER) || !scalar_check (kind, 1)
1716 : 108 : || !positive_check (1, kind))
1717 : 16 : return false;
1718 : :
1719 : : /* Get the kind, reporting error on non-constant or overflow. */
1720 : 48 : gfc_current_locus = kind->where;
1721 : 48 : if (gfc_extract_int (kind, &k, 1))
1722 : : return false;
1723 : 44 : if (gfc_validate_kind (BT_INTEGER, k, true) == -1)
1724 : : {
1725 : 4 : gfc_error ("%qs argument of %qs intrinsic at %L shall specify a "
1726 : 4 : "valid integer kind", gfc_current_intrinsic_arg[1]->name,
1727 : : gfc_current_intrinsic, &kind->where);
1728 : 4 : return false;
1729 : : }
1730 : : }
1731 : : return true;
1732 : : }
1733 : :
1734 : :
1735 : : bool
1736 : 1 : gfc_check_get_team (gfc_expr *level)
1737 : : {
1738 : 1 : if (level)
1739 : : {
1740 : 0 : gfc_error ("%qs argument of %qs intrinsic at %L not yet supported",
1741 : 0 : gfc_current_intrinsic_arg[0]->name, gfc_current_intrinsic,
1742 : : &level->where);
1743 : 0 : return false;
1744 : : }
1745 : : return true;
1746 : : }
1747 : :
1748 : :
1749 : : bool
1750 : 23 : gfc_check_atomic_cas (gfc_expr *atom, gfc_expr *old, gfc_expr *compare,
1751 : : gfc_expr *new_val, gfc_expr *stat)
1752 : : {
1753 : 23 : if (atom->expr_type == EXPR_FUNCTION
1754 : 4 : && atom->value.function.isym
1755 : 4 : && atom->value.function.isym->id == GFC_ISYM_CAF_GET)
1756 : 4 : atom = atom->value.function.actual->expr;
1757 : :
1758 : 23 : if (!gfc_check_atomic (atom, 0, new_val, 3, stat, 4))
1759 : : return false;
1760 : :
1761 : 16 : if (!scalar_check (old, 1) || !scalar_check (compare, 2))
1762 : 0 : return false;
1763 : :
1764 : 16 : if (!same_type_check (atom, 0, old, 1))
1765 : : return false;
1766 : :
1767 : 14 : if (!same_type_check (atom, 0, compare, 2))
1768 : : return false;
1769 : :
1770 : 12 : if (!gfc_check_vardef_context (atom, false, false, false, NULL))
1771 : : {
1772 : 0 : gfc_error ("ATOM argument of the %s intrinsic function at %L shall be "
1773 : : "definable", gfc_current_intrinsic, &atom->where);
1774 : 0 : return false;
1775 : : }
1776 : :
1777 : 12 : if (!gfc_check_vardef_context (old, false, false, false, NULL))
1778 : : {
1779 : 0 : gfc_error ("OLD argument of the %s intrinsic function at %L shall be "
1780 : : "definable", gfc_current_intrinsic, &old->where);
1781 : 0 : return false;
1782 : : }
1783 : :
1784 : : return true;
1785 : : }
1786 : :
1787 : : bool
1788 : 70 : gfc_check_event_query (gfc_expr *event, gfc_expr *count, gfc_expr *stat)
1789 : : {
1790 : 70 : if (event->ts.type != BT_DERIVED
1791 : 70 : || event->ts.u.derived->from_intmod != INTMOD_ISO_FORTRAN_ENV
1792 : 70 : || event->ts.u.derived->intmod_sym_id != ISOFORTRAN_EVENT_TYPE)
1793 : : {
1794 : 0 : gfc_error ("EVENT argument at %L to the intrinsic EVENT_QUERY "
1795 : : "shall be of type EVENT_TYPE", &event->where);
1796 : 0 : return false;
1797 : : }
1798 : :
1799 : 70 : if (!scalar_check (event, 0))
1800 : : return false;
1801 : :
1802 : 70 : if (!gfc_check_vardef_context (count, false, false, false, NULL))
1803 : : {
1804 : 0 : gfc_error ("COUNT argument of the EVENT_QUERY intrinsic function at %L "
1805 : : "shall be definable", &count->where);
1806 : 0 : return false;
1807 : : }
1808 : :
1809 : 70 : if (!type_check (count, 1, BT_INTEGER))
1810 : : return false;
1811 : :
1812 : 70 : int i = gfc_validate_kind (BT_INTEGER, count->ts.kind, false);
1813 : 70 : int j = gfc_validate_kind (BT_INTEGER, gfc_default_integer_kind, false);
1814 : :
1815 : 70 : if (gfc_integer_kinds[i].range < gfc_integer_kinds[j].range)
1816 : : {
1817 : 0 : gfc_error ("COUNT argument of the EVENT_QUERY intrinsic function at %L "
1818 : : "shall have at least the range of the default integer",
1819 : : &count->where);
1820 : 0 : return false;
1821 : : }
1822 : :
1823 : 70 : if (stat != NULL)
1824 : : {
1825 : 12 : if (!type_check (stat, 2, BT_INTEGER))
1826 : : return false;
1827 : 12 : if (!scalar_check (stat, 2))
1828 : : return false;
1829 : 12 : if (!variable_check (stat, 2, false))
1830 : : return false;
1831 : :
1832 : 12 : if (!gfc_notify_std (GFC_STD_F2018, "STAT= argument to %s at %L",
1833 : : gfc_current_intrinsic, &stat->where))
1834 : : return false;
1835 : : }
1836 : :
1837 : : return true;
1838 : : }
1839 : :
1840 : :
1841 : : bool
1842 : 54 : gfc_check_atomic_fetch_op (gfc_expr *atom, gfc_expr *value, gfc_expr *old,
1843 : : gfc_expr *stat)
1844 : : {
1845 : 54 : if (atom->expr_type == EXPR_FUNCTION
1846 : 10 : && atom->value.function.isym
1847 : 10 : && atom->value.function.isym->id == GFC_ISYM_CAF_GET)
1848 : 10 : atom = atom->value.function.actual->expr;
1849 : :
1850 : 54 : if (atom->ts.type != BT_INTEGER || atom->ts.kind != gfc_atomic_int_kind)
1851 : : {
1852 : 4 : gfc_error ("ATOM argument at %L to intrinsic function %s shall be an "
1853 : : "integer of ATOMIC_INT_KIND", &atom->where,
1854 : : gfc_current_intrinsic);
1855 : 4 : return false;
1856 : : }
1857 : :
1858 : 50 : if (!gfc_check_atomic (atom, 0, value, 1, stat, 3))
1859 : : return false;
1860 : :
1861 : 38 : if (!scalar_check (old, 2))
1862 : : return false;
1863 : :
1864 : 38 : if (!same_type_check (atom, 0, old, 2))
1865 : : return false;
1866 : :
1867 : 34 : if (!gfc_check_vardef_context (atom, false, false, false, NULL))
1868 : : {
1869 : 0 : gfc_error ("ATOM argument of the %s intrinsic function at %L shall be "
1870 : : "definable", gfc_current_intrinsic, &atom->where);
1871 : 0 : return false;
1872 : : }
1873 : :
1874 : 34 : if (!gfc_check_vardef_context (old, false, false, false, NULL))
1875 : : {
1876 : 0 : gfc_error ("OLD argument of the %s intrinsic function at %L shall be "
1877 : : "definable", gfc_current_intrinsic, &old->where);
1878 : 0 : return false;
1879 : : }
1880 : :
1881 : : return true;
1882 : : }
1883 : :
1884 : :
1885 : : /* BESJN and BESYN functions. */
1886 : :
1887 : : bool
1888 : 234 : gfc_check_besn (gfc_expr *n, gfc_expr *x)
1889 : : {
1890 : 234 : if (!type_check (n, 0, BT_INTEGER))
1891 : : return false;
1892 : 234 : if (n->expr_type == EXPR_CONSTANT)
1893 : : {
1894 : 59 : int i;
1895 : 59 : gfc_extract_int (n, &i);
1896 : 59 : if (i < 0 && !gfc_notify_std (GFC_STD_GNU, "Negative argument "
1897 : : "N at %L", &n->where))
1898 : 2 : return false;
1899 : : }
1900 : :
1901 : 232 : if (!type_check (x, 1, BT_REAL))
1902 : : return false;
1903 : :
1904 : : return true;
1905 : : }
1906 : :
1907 : :
1908 : : /* Transformational version of the Bessel JN and YN functions. */
1909 : :
1910 : : bool
1911 : 66 : gfc_check_bessel_n2 (gfc_expr *n1, gfc_expr *n2, gfc_expr *x)
1912 : : {
1913 : 66 : if (!type_check (n1, 0, BT_INTEGER))
1914 : : return false;
1915 : 66 : if (!scalar_check (n1, 0))
1916 : : return false;
1917 : 66 : if (!nonnegative_check ("N1", n1))
1918 : : return false;
1919 : :
1920 : 65 : if (!type_check (n2, 1, BT_INTEGER))
1921 : : return false;
1922 : 65 : if (!scalar_check (n2, 1))
1923 : : return false;
1924 : 65 : if (!nonnegative_check ("N2", n2))
1925 : : return false;
1926 : :
1927 : 65 : if (!type_check (x, 2, BT_REAL))
1928 : : return false;
1929 : 65 : if (!scalar_check (x, 2))
1930 : : return false;
1931 : :
1932 : : return true;
1933 : : }
1934 : :
1935 : :
1936 : : bool
1937 : 1182 : gfc_check_bge_bgt_ble_blt (gfc_expr *i, gfc_expr *j)
1938 : : {
1939 : 1182 : extern int gfc_max_integer_kind;
1940 : :
1941 : : /* If i and j are both BOZ, convert to widest INTEGER. */
1942 : 1182 : if (i->ts.type == BT_BOZ && j->ts.type == BT_BOZ)
1943 : : {
1944 : 24 : if (!gfc_boz2int (i, gfc_max_integer_kind))
1945 : : return false;
1946 : 24 : if (!gfc_boz2int (j, gfc_max_integer_kind))
1947 : : return false;
1948 : : }
1949 : :
1950 : : /* If i is BOZ and j is integer, convert i to type of j. */
1951 : 24 : if (i->ts.type == BT_BOZ && j->ts.type == BT_INTEGER
1952 : 1206 : && !gfc_boz2int (i, j->ts.kind))
1953 : : return false;
1954 : :
1955 : : /* If j is BOZ and i is integer, convert j to type of i. */
1956 : 24 : if (j->ts.type == BT_BOZ && i->ts.type == BT_INTEGER
1957 : 1206 : && !gfc_boz2int (j, i->ts.kind))
1958 : : return false;
1959 : :
1960 : 1182 : if (!type_check (i, 0, BT_INTEGER))
1961 : : return false;
1962 : :
1963 : 1182 : if (!type_check (j, 1, BT_INTEGER))
1964 : : return false;
1965 : :
1966 : : return true;
1967 : : }
1968 : :
1969 : :
1970 : : bool
1971 : 662 : gfc_check_bitfcn (gfc_expr *i, gfc_expr *pos)
1972 : : {
1973 : 662 : if (!type_check (i, 0, BT_INTEGER))
1974 : : return false;
1975 : :
1976 : 662 : if (!type_check (pos, 1, BT_INTEGER))
1977 : : return false;
1978 : :
1979 : 662 : if (!nonnegative_check ("pos", pos))
1980 : : return false;
1981 : :
1982 : 647 : if (!less_than_bitsize1 ("i", i, "pos", pos, false))
1983 : : return false;
1984 : :
1985 : : return true;
1986 : : }
1987 : :
1988 : :
1989 : : bool
1990 : 963 : gfc_check_char (gfc_expr *i, gfc_expr *kind)
1991 : : {
1992 : 963 : if (i->ts.type == BT_BOZ)
1993 : : {
1994 : 0 : if (gfc_invalid_boz (G_("BOZ literal constant at %L cannot appear in "
1995 : : "CHAR intrinsic subprogram"), &i->where))
1996 : : return false;
1997 : :
1998 : 0 : if (!gfc_boz2int (i, gfc_default_integer_kind))
1999 : : return false;
2000 : : }
2001 : :
2002 : 963 : if (!type_check (i, 0, BT_INTEGER))
2003 : : return false;
2004 : :
2005 : 963 : if (!kind_check (kind, 1, BT_CHARACTER))
2006 : : return false;
2007 : :
2008 : : return true;
2009 : : }
2010 : :
2011 : :
2012 : : bool
2013 : 5 : gfc_check_chdir (gfc_expr *dir)
2014 : : {
2015 : 5 : if (!type_check (dir, 0, BT_CHARACTER))
2016 : : return false;
2017 : 5 : if (!kind_value_check (dir, 0, gfc_default_character_kind))
2018 : : return false;
2019 : :
2020 : : return true;
2021 : : }
2022 : :
2023 : :
2024 : : bool
2025 : 11 : gfc_check_chdir_sub (gfc_expr *dir, gfc_expr *status)
2026 : : {
2027 : 11 : if (!type_check (dir, 0, BT_CHARACTER))
2028 : : return false;
2029 : 11 : if (!kind_value_check (dir, 0, gfc_default_character_kind))
2030 : : return false;
2031 : :
2032 : 9 : if (status == NULL)
2033 : : return true;
2034 : :
2035 : 7 : if (!type_check (status, 1, BT_INTEGER))
2036 : : return false;
2037 : 7 : if (!scalar_check (status, 1))
2038 : : return false;
2039 : :
2040 : : return true;
2041 : : }
2042 : :
2043 : :
2044 : : bool
2045 : 40 : gfc_check_chmod (gfc_expr *name, gfc_expr *mode)
2046 : : {
2047 : 40 : if (!type_check (name, 0, BT_CHARACTER))
2048 : : return false;
2049 : 40 : if (!kind_value_check (name, 0, gfc_default_character_kind))
2050 : : return false;
2051 : :
2052 : 38 : if (!type_check (mode, 1, BT_CHARACTER))
2053 : : return false;
2054 : 38 : if (!kind_value_check (mode, 1, gfc_default_character_kind))
2055 : : return false;
2056 : :
2057 : : return true;
2058 : : }
2059 : :
2060 : :
2061 : : bool
2062 : 20 : gfc_check_chmod_sub (gfc_expr *name, gfc_expr *mode, gfc_expr *status)
2063 : : {
2064 : 20 : if (!type_check (name, 0, BT_CHARACTER))
2065 : : return false;
2066 : 20 : if (!kind_value_check (name, 0, gfc_default_character_kind))
2067 : : return false;
2068 : :
2069 : 16 : if (!type_check (mode, 1, BT_CHARACTER))
2070 : : return false;
2071 : 16 : if (!kind_value_check (mode, 1, gfc_default_character_kind))
2072 : : return false;
2073 : :
2074 : 14 : if (status == NULL)
2075 : : return true;
2076 : :
2077 : 13 : if (!type_check (status, 2, BT_INTEGER))
2078 : : return false;
2079 : :
2080 : 13 : if (!scalar_check (status, 2))
2081 : : return false;
2082 : :
2083 : : return true;
2084 : : }
2085 : :
2086 : :
2087 : : bool
2088 : 2142 : gfc_check_cmplx (gfc_expr *x, gfc_expr *y, gfc_expr *kind)
2089 : : {
2090 : 2142 : int k;
2091 : :
2092 : : /* Check kind first, because it may be needed in conversion of a BOZ. */
2093 : 2142 : if (kind)
2094 : : {
2095 : 1200 : if (!kind_check (kind, 2, BT_COMPLEX))
2096 : : return false;
2097 : 1200 : gfc_extract_int (kind, &k);
2098 : : }
2099 : : else
2100 : 942 : k = gfc_default_complex_kind;
2101 : :
2102 : 2142 : if (x->ts.type == BT_BOZ && !gfc_boz2real (x, k))
2103 : : return false;
2104 : :
2105 : 2142 : if (!numeric_check (x, 0))
2106 : : return false;
2107 : :
2108 : 2142 : if (y != NULL)
2109 : : {
2110 : 1990 : if (y->ts.type == BT_BOZ && !gfc_boz2real (y, k))
2111 : : return false;
2112 : :
2113 : 1990 : if (!numeric_check (y, 1))
2114 : : return false;
2115 : :
2116 : 1990 : if (x->ts.type == BT_COMPLEX)
2117 : : {
2118 : 0 : gfc_error ("%qs argument of %qs intrinsic at %L must not be "
2119 : : "present if %<x%> is COMPLEX",
2120 : 0 : gfc_current_intrinsic_arg[1]->name, gfc_current_intrinsic,
2121 : : &y->where);
2122 : 0 : return false;
2123 : : }
2124 : :
2125 : 1990 : if (y->ts.type == BT_COMPLEX)
2126 : : {
2127 : 1 : gfc_error ("%qs argument of %qs intrinsic at %L must have a type "
2128 : : "of either REAL or INTEGER",
2129 : 1 : gfc_current_intrinsic_arg[1]->name, gfc_current_intrinsic,
2130 : : &y->where);
2131 : 1 : return false;
2132 : : }
2133 : : }
2134 : :
2135 : 2141 : if (!kind && warn_conversion
2136 : 6 : && x->ts.type == BT_REAL && x->ts.kind > gfc_default_real_kind)
2137 : 2 : gfc_warning_now (OPT_Wconversion, "Conversion from %s to default-kind "
2138 : : "COMPLEX(%d) at %L might lose precision, consider using "
2139 : : "the KIND argument", gfc_typename (&x->ts),
2140 : : gfc_default_real_kind, &x->where);
2141 : 2139 : else if (y && !kind && warn_conversion
2142 : 4 : && y->ts.type == BT_REAL && y->ts.kind > gfc_default_real_kind)
2143 : 1 : gfc_warning_now (OPT_Wconversion, "Conversion from %s to default-kind "
2144 : : "COMPLEX(%d) at %L might lose precision, consider using "
2145 : : "the KIND argument", gfc_typename (&y->ts),
2146 : : gfc_default_real_kind, &y->where);
2147 : : return true;
2148 : : }
2149 : :
2150 : :
2151 : : static bool
2152 : 156 : check_co_collective (gfc_expr *a, gfc_expr *image_idx, gfc_expr *stat,
2153 : : gfc_expr *errmsg, bool co_reduce)
2154 : : {
2155 : 156 : if (!variable_check (a, 0, false))
2156 : : return false;
2157 : :
2158 : 151 : if (!gfc_check_vardef_context (a, false, false, false, "argument 'A' with "
2159 : : "INTENT(INOUT)"))
2160 : : return false;
2161 : :
2162 : : /* Fortran 2008, 12.5.2.4, paragraph 18. */
2163 : 150 : if (gfc_has_vector_subscript (a))
2164 : : {
2165 : 4 : gfc_error ("Argument %<A%> with INTENT(INOUT) at %L of the intrinsic "
2166 : : "subroutine %s shall not have a vector subscript",
2167 : : &a->where, gfc_current_intrinsic);
2168 : 4 : return false;
2169 : : }
2170 : :
2171 : 146 : if (gfc_is_coindexed (a))
2172 : : {
2173 : 5 : gfc_error ("The A argument at %L to the intrinsic %s shall not be "
2174 : : "coindexed", &a->where, gfc_current_intrinsic);
2175 : 5 : return false;
2176 : : }
2177 : :
2178 : 141 : if (image_idx != NULL)
2179 : : {
2180 : 136 : if (!type_check (image_idx, co_reduce ? 2 : 1, BT_INTEGER))
2181 : : return false;
2182 : 70 : if (!scalar_check (image_idx, co_reduce ? 2 : 1))
2183 : : return false;
2184 : : }
2185 : :
2186 : 135 : if (stat != NULL)
2187 : : {
2188 : 132 : if (!type_check (stat, co_reduce ? 3 : 2, BT_INTEGER))
2189 : : return false;
2190 : 70 : if (!scalar_check (stat, co_reduce ? 3 : 2))
2191 : : return false;
2192 : 67 : if (!variable_check (stat, co_reduce ? 3 : 2, false))
2193 : : return false;
2194 : 64 : if (stat->ts.kind != 4)
2195 : : {
2196 : 3 : gfc_error ("The stat= argument at %L must be a kind=4 integer "
2197 : : "variable", &stat->where);
2198 : 3 : return false;
2199 : : }
2200 : : }
2201 : :
2202 : 123 : if (errmsg != NULL)
2203 : : {
2204 : 96 : if (!type_check (errmsg, co_reduce ? 4 : 3, BT_CHARACTER))
2205 : : return false;
2206 : 49 : if (!scalar_check (errmsg, co_reduce ? 4 : 3))
2207 : : return false;
2208 : 46 : if (!variable_check (errmsg, co_reduce ? 4 : 3, false))
2209 : : return false;
2210 : 43 : if (errmsg->ts.kind != 1)
2211 : : {
2212 : 3 : gfc_error ("The errmsg= argument at %L must be a default-kind "
2213 : : "character variable", &errmsg->where);
2214 : 3 : return false;
2215 : : }
2216 : : }
2217 : :
2218 : 111 : if (flag_coarray == GFC_FCOARRAY_NONE)
2219 : : {
2220 : 1 : gfc_fatal_error ("Coarrays disabled at %L, use %<-fcoarray=%> to enable",
2221 : : &a->where);
2222 : : return false;
2223 : : }
2224 : :
2225 : : return true;
2226 : : }
2227 : :
2228 : :
2229 : : bool
2230 : 48 : gfc_check_co_broadcast (gfc_expr *a, gfc_expr *source_image, gfc_expr *stat,
2231 : : gfc_expr *errmsg)
2232 : : {
2233 : 48 : if (a->ts.type == BT_CLASS || gfc_expr_attr (a).alloc_comp)
2234 : : {
2235 : 0 : gfc_error ("Support for the A argument at %L which is polymorphic A "
2236 : : "argument or has allocatable components is not yet "
2237 : : "implemented", &a->where);
2238 : 0 : return false;
2239 : : }
2240 : 48 : return check_co_collective (a, source_image, stat, errmsg, false);
2241 : : }
2242 : :
2243 : :
2244 : : bool
2245 : 63 : gfc_check_co_reduce (gfc_expr *a, gfc_expr *op, gfc_expr *result_image,
2246 : : gfc_expr *stat, gfc_expr *errmsg)
2247 : : {
2248 : 63 : symbol_attribute attr;
2249 : 63 : gfc_formal_arglist *formal;
2250 : 63 : gfc_symbol *sym;
2251 : :
2252 : 63 : if (a->ts.type == BT_CLASS)
2253 : : {
2254 : 0 : gfc_error ("The A argument at %L of CO_REDUCE shall not be polymorphic",
2255 : : &a->where);
2256 : 0 : return false;
2257 : : }
2258 : :
2259 : 63 : if (gfc_expr_attr (a).alloc_comp)
2260 : : {
2261 : 0 : gfc_error ("Support for the A argument at %L with allocatable components"
2262 : : " is not yet implemented", &a->where);
2263 : 0 : return false;
2264 : : }
2265 : :
2266 : 63 : if (!check_co_collective (a, result_image, stat, errmsg, true))
2267 : : return false;
2268 : :
2269 : 50 : if (!gfc_resolve_expr (op))
2270 : : return false;
2271 : :
2272 : 50 : attr = gfc_expr_attr (op);
2273 : 50 : if (!attr.pure || !attr.function)
2274 : : {
2275 : 7 : gfc_error ("OPERATION argument at %L must be a PURE function",
2276 : : &op->where);
2277 : 7 : return false;
2278 : : }
2279 : :
2280 : 43 : if (attr.intrinsic)
2281 : : {
2282 : : /* None of the intrinsics fulfills the criteria of taking two arguments,
2283 : : returning the same type and kind as the arguments and being permitted
2284 : : as actual argument. */
2285 : 1 : gfc_error ("Intrinsic function %s at %L is not permitted for CO_REDUCE",
2286 : 1 : op->symtree->n.sym->name, &op->where);
2287 : 1 : return false;
2288 : : }
2289 : :
2290 : 42 : if (gfc_is_proc_ptr_comp (op))
2291 : : {
2292 : 16 : gfc_component *comp = gfc_get_proc_ptr_comp (op);
2293 : 16 : sym = comp->ts.interface;
2294 : : }
2295 : : else
2296 : 26 : sym = op->symtree->n.sym;
2297 : :
2298 : 42 : formal = sym->formal;
2299 : :
2300 : 42 : if (!formal || !formal->next || formal->next->next)
2301 : : {
2302 : 4 : gfc_error ("The function passed as OPERATION at %L shall have two "
2303 : : "arguments", &op->where);
2304 : 4 : return false;
2305 : : }
2306 : :
2307 : 38 : if (sym->result->ts.type == BT_UNKNOWN)
2308 : 0 : gfc_set_default_type (sym->result, 0, NULL);
2309 : :
2310 : 38 : if (!gfc_compare_types (&a->ts, &sym->result->ts))
2311 : : {
2312 : 4 : gfc_error ("The A argument at %L has type %s but the function passed as "
2313 : : "OPERATION at %L returns %s",
2314 : : &a->where, gfc_typename (a), &op->where,
2315 : 4 : gfc_typename (&sym->result->ts));
2316 : 4 : return false;
2317 : : }
2318 : 34 : if (!gfc_compare_types (&a->ts, &formal->sym->ts)
2319 : 34 : || !gfc_compare_types (&a->ts, &formal->next->sym->ts))
2320 : : {
2321 : 0 : gfc_error ("The function passed as OPERATION at %L has arguments of type "
2322 : : "%s and %s but shall have type %s", &op->where,
2323 : 0 : gfc_typename (&formal->sym->ts),
2324 : 0 : gfc_typename (&formal->next->sym->ts), gfc_typename (a));
2325 : 0 : return false;
2326 : : }
2327 : 34 : if (op->rank || attr.allocatable || attr.pointer || formal->sym->as
2328 : 32 : || formal->next->sym->as || formal->sym->attr.allocatable
2329 : 30 : || formal->next->sym->attr.allocatable || formal->sym->attr.pointer
2330 : 28 : || formal->next->sym->attr.pointer)
2331 : : {
2332 : 6 : gfc_error ("The function passed as OPERATION at %L shall have scalar "
2333 : : "nonallocatable nonpointer arguments and return a "
2334 : : "nonallocatable nonpointer scalar", &op->where);
2335 : 6 : return false;
2336 : : }
2337 : :
2338 : 28 : if (formal->sym->attr.value != formal->next->sym->attr.value)
2339 : : {
2340 : 2 : gfc_error ("The function passed as OPERATION at %L shall have the VALUE "
2341 : : "attribute either for none or both arguments", &op->where);
2342 : 2 : return false;
2343 : : }
2344 : :
2345 : 26 : if (formal->sym->attr.target != formal->next->sym->attr.target)
2346 : : {
2347 : 2 : gfc_error ("The function passed as OPERATION at %L shall have the TARGET "
2348 : : "attribute either for none or both arguments", &op->where);
2349 : 2 : return false;
2350 : : }
2351 : :
2352 : 24 : if (formal->sym->attr.asynchronous != formal->next->sym->attr.asynchronous)
2353 : : {
2354 : 2 : gfc_error ("The function passed as OPERATION at %L shall have the "
2355 : : "ASYNCHRONOUS attribute either for none or both arguments",
2356 : : &op->where);
2357 : 2 : return false;
2358 : : }
2359 : :
2360 : 22 : if (formal->sym->attr.optional || formal->next->sym->attr.optional)
2361 : : {
2362 : 2 : gfc_error ("The function passed as OPERATION at %L shall not have the "
2363 : : "OPTIONAL attribute for either of the arguments", &op->where);
2364 : 2 : return false;
2365 : : }
2366 : :
2367 : 20 : if (a->ts.type == BT_CHARACTER)
2368 : : {
2369 : 7 : gfc_charlen *cl;
2370 : 7 : unsigned long actual_size, formal_size1, formal_size2, result_size;
2371 : :
2372 : 7 : cl = a->ts.u.cl;
2373 : 7 : actual_size = cl && cl->length && cl->length->expr_type == EXPR_CONSTANT
2374 : 14 : ? mpz_get_ui (cl->length->value.integer) : 0;
2375 : :
2376 : 7 : cl = formal->sym->ts.u.cl;
2377 : 7 : formal_size1 = cl && cl->length && cl->length->expr_type == EXPR_CONSTANT
2378 : 14 : ? mpz_get_ui (cl->length->value.integer) : 0;
2379 : :
2380 : 7 : cl = formal->next->sym->ts.u.cl;
2381 : 7 : formal_size2 = cl && cl->length && cl->length->expr_type == EXPR_CONSTANT
2382 : 14 : ? mpz_get_ui (cl->length->value.integer) : 0;
2383 : :
2384 : 7 : cl = sym->ts.u.cl;
2385 : 7 : result_size = cl && cl->length && cl->length->expr_type == EXPR_CONSTANT
2386 : 14 : ? mpz_get_ui (cl->length->value.integer) : 0;
2387 : :
2388 : 7 : if (actual_size
2389 : 7 : && ((formal_size1 && actual_size != formal_size1)
2390 : 5 : || (formal_size2 && actual_size != formal_size2)))
2391 : : {
2392 : 2 : gfc_error ("The character length of the A argument at %L and of the "
2393 : : "arguments of the OPERATION at %L shall be the same",
2394 : : &a->where, &op->where);
2395 : 2 : return false;
2396 : : }
2397 : 5 : if (actual_size && result_size && actual_size != result_size)
2398 : : {
2399 : 2 : gfc_error ("The character length of the A argument at %L and of the "
2400 : : "function result of the OPERATION at %L shall be the same",
2401 : : &a->where, &op->where);
2402 : 2 : return false;
2403 : : }
2404 : : }
2405 : :
2406 : : return true;
2407 : : }
2408 : :
2409 : :
2410 : : bool
2411 : 32 : gfc_check_co_minmax (gfc_expr *a, gfc_expr *result_image, gfc_expr *stat,
2412 : : gfc_expr *errmsg)
2413 : : {
2414 : 32 : if (a->ts.type != BT_INTEGER && a->ts.type != BT_REAL
2415 : : && a->ts.type != BT_CHARACTER)
2416 : : {
2417 : 2 : gfc_error ("%qs argument of %qs intrinsic at %L shall be of type "
2418 : : "integer, real or character",
2419 : 2 : gfc_current_intrinsic_arg[0]->name, gfc_current_intrinsic,
2420 : : &a->where);
2421 : 2 : return false;
2422 : : }
2423 : 30 : return check_co_collective (a, result_image, stat, errmsg, false);
2424 : : }
2425 : :
2426 : :
2427 : : bool
2428 : 16 : gfc_check_co_sum (gfc_expr *a, gfc_expr *result_image, gfc_expr *stat,
2429 : : gfc_expr *errmsg)
2430 : : {
2431 : 16 : if (!numeric_check (a, 0))
2432 : : return false;
2433 : 15 : return check_co_collective (a, result_image, stat, errmsg, false);
2434 : : }
2435 : :
2436 : :
2437 : : bool
2438 : 54 : gfc_check_complex (gfc_expr *x, gfc_expr *y)
2439 : : {
2440 : 54 : if (!boz_args_check (x, y))
2441 : : return false;
2442 : :
2443 : 53 : if (x->ts.type == BT_BOZ)
2444 : : {
2445 : 16 : if (gfc_invalid_boz (G_("BOZ constant at %L cannot appear in the COMPLEX"
2446 : : " intrinsic subprogram"), &x->where))
2447 : : {
2448 : 2 : reset_boz (x);
2449 : 2 : return false;
2450 : : }
2451 : 14 : if (y->ts.type == BT_INTEGER && !gfc_boz2int (x, y->ts.kind))
2452 : : return false;
2453 : 14 : if (y->ts.type == BT_REAL && !gfc_boz2real (x, y->ts.kind))
2454 : : return false;
2455 : : }
2456 : :
2457 : 51 : if (y->ts.type == BT_BOZ)
2458 : : {
2459 : 0 : if (gfc_invalid_boz (G_("BOZ constant at %L cannot appear in the COMPLEX"
2460 : : " intrinsic subprogram"), &y->where))
2461 : : {
2462 : 0 : reset_boz (y);
2463 : 0 : return false;
2464 : : }
2465 : 0 : if (x->ts.type == BT_INTEGER && !gfc_boz2int (y, x->ts.kind))
2466 : : return false;
2467 : 0 : if (x->ts.type == BT_REAL && !gfc_boz2real (y, x->ts.kind))
2468 : : return false;
2469 : : }
2470 : :
2471 : 51 : if (!int_or_real_check (x, 0))
2472 : : return false;
2473 : 50 : if (!scalar_check (x, 0))
2474 : : return false;
2475 : :
2476 : 50 : if (!int_or_real_check (y, 1))
2477 : : return false;
2478 : 49 : if (!scalar_check (y, 1))
2479 : : return false;
2480 : :
2481 : : return true;
2482 : : }
2483 : :
2484 : :
2485 : : bool
2486 : 348 : gfc_check_count (gfc_expr *mask, gfc_expr *dim, gfc_expr *kind)
2487 : : {
2488 : 348 : if (!logical_array_check (mask, 0))
2489 : : return false;
2490 : 348 : if (!dim_check (dim, 1, false))
2491 : : return false;
2492 : 348 : if (!dim_rank_check (dim, mask, 0))
2493 : : return false;
2494 : 348 : if (!kind_check (kind, 2, BT_INTEGER))
2495 : : return false;
2496 : 348 : if (kind && !gfc_notify_std (GFC_STD_F2003, "%qs intrinsic "
2497 : : "with KIND argument at %L",
2498 : : gfc_current_intrinsic, &kind->where))
2499 : : return false;
2500 : :
2501 : : return true;
2502 : : }
2503 : :
2504 : :
2505 : : bool
2506 : 682 : gfc_check_cshift (gfc_expr *array, gfc_expr *shift, gfc_expr *dim)
2507 : : {
2508 : 682 : if (!array_check (array, 0))
2509 : : return false;
2510 : :
2511 : 682 : if (!type_check (shift, 1, BT_INTEGER))
2512 : : return false;
2513 : :
2514 : 681 : if (!dim_check (dim, 2, true))
2515 : : return false;
2516 : :
2517 : 681 : if (!dim_rank_check (dim, array, false))
2518 : : return false;
2519 : :
2520 : 681 : if (array->rank == 1 || shift->rank == 0)
2521 : : {
2522 : 491 : if (!scalar_check (shift, 1))
2523 : : return false;
2524 : : }
2525 : 190 : else if (shift->rank == array->rank - 1)
2526 : : {
2527 : 189 : int d;
2528 : 189 : if (!dim)
2529 : 48 : d = 1;
2530 : 141 : else if (dim->expr_type == EXPR_CONSTANT)
2531 : 110 : gfc_extract_int (dim, &d);
2532 : : else
2533 : 31 : d = -1;
2534 : :
2535 : 189 : if (d > 0)
2536 : : {
2537 : : int i, j;
2538 : 539 : for (i = 0, j = 0; i < array->rank; i++)
2539 : 381 : if (i != d - 1)
2540 : : {
2541 : 223 : if (!identical_dimen_shape (array, i, shift, j))
2542 : : {
2543 : 0 : gfc_error ("%qs argument of %qs intrinsic at %L has "
2544 : : "invalid shape in dimension %d (%ld/%ld)",
2545 : 0 : gfc_current_intrinsic_arg[1]->name,
2546 : : gfc_current_intrinsic, &shift->where, i + 1,
2547 : 0 : mpz_get_si (array->shape[i]),
2548 : 0 : mpz_get_si (shift->shape[j]));
2549 : 0 : return false;
2550 : : }
2551 : :
2552 : 223 : j += 1;
2553 : : }
2554 : : }
2555 : : }
2556 : : else
2557 : : {
2558 : 1 : gfc_error ("%qs argument of intrinsic %qs at %L of must have rank "
2559 : 1 : "%d or be a scalar", gfc_current_intrinsic_arg[1]->name,
2560 : : gfc_current_intrinsic, &shift->where, array->rank - 1);
2561 : 1 : return false;
2562 : : }
2563 : :
2564 : : return true;
2565 : : }
2566 : :
2567 : :
2568 : : bool
2569 : 0 : gfc_check_ctime (gfc_expr *time)
2570 : : {
2571 : 0 : if (!scalar_check (time, 0))
2572 : : return false;
2573 : :
2574 : 0 : if (!type_check (time, 0, BT_INTEGER))
2575 : : return false;
2576 : :
2577 : : return true;
2578 : : }
2579 : :
2580 : :
2581 : 423 : bool gfc_check_datan2 (gfc_expr *y, gfc_expr *x)
2582 : : {
2583 : 423 : if (!double_check (y, 0) || !double_check (x, 1))
2584 : 247 : return false;
2585 : :
2586 : : return true;
2587 : : }
2588 : :
2589 : : bool
2590 : 163 : gfc_check_dcmplx (gfc_expr *x, gfc_expr *y)
2591 : : {
2592 : 163 : if (x->ts.type == BT_BOZ && !gfc_boz2real (x, gfc_default_double_kind))
2593 : : return false;
2594 : :
2595 : 163 : if (!numeric_check (x, 0))
2596 : : return false;
2597 : :
2598 : 163 : if (y != NULL)
2599 : : {
2600 : 162 : if (y->ts.type == BT_BOZ && !gfc_boz2real (y, gfc_default_double_kind))
2601 : : return false;
2602 : :
2603 : 162 : if (!numeric_check (y, 1))
2604 : : return false;
2605 : :
2606 : 162 : if (x->ts.type == BT_COMPLEX)
2607 : : {
2608 : 0 : gfc_error ("%qs argument of %qs intrinsic at %L must not be "
2609 : : "present if %<x%> is COMPLEX",
2610 : 0 : gfc_current_intrinsic_arg[1]->name, gfc_current_intrinsic,
2611 : : &y->where);
2612 : 0 : return false;
2613 : : }
2614 : :
2615 : 162 : if (y->ts.type == BT_COMPLEX)
2616 : : {
2617 : 1 : gfc_error ("%qs argument of %qs intrinsic at %L must have a type "
2618 : : "of either REAL or INTEGER",
2619 : 1 : gfc_current_intrinsic_arg[1]->name, gfc_current_intrinsic,
2620 : : &y->where);
2621 : 1 : return false;
2622 : : }
2623 : : }
2624 : :
2625 : : return true;
2626 : : }
2627 : :
2628 : :
2629 : : bool
2630 : 223 : gfc_check_dble (gfc_expr *x)
2631 : : {
2632 : 223 : if (x->ts.type == BT_BOZ && !gfc_boz2real (x, gfc_default_double_kind))
2633 : : return false;
2634 : :
2635 : 223 : if (!numeric_check (x, 0))
2636 : : return false;
2637 : :
2638 : : return true;
2639 : : }
2640 : :
2641 : :
2642 : : bool
2643 : 34 : gfc_check_digits (gfc_expr *x)
2644 : : {
2645 : 34 : if (!int_or_real_check (x, 0))
2646 : : return false;
2647 : :
2648 : : return true;
2649 : : }
2650 : :
2651 : :
2652 : : bool
2653 : 171 : gfc_check_dot_product (gfc_expr *vector_a, gfc_expr *vector_b)
2654 : : {
2655 : 171 : switch (vector_a->ts.type)
2656 : : {
2657 : 36 : case BT_LOGICAL:
2658 : 36 : if (!type_check (vector_b, 1, BT_LOGICAL))
2659 : : return false;
2660 : : break;
2661 : :
2662 : 135 : case BT_INTEGER:
2663 : 135 : case BT_REAL:
2664 : 135 : case BT_COMPLEX:
2665 : 135 : if (!numeric_check (vector_b, 1))
2666 : : return false;
2667 : : break;
2668 : :
2669 : 0 : default:
2670 : 0 : gfc_error ("%qs argument of %qs intrinsic at %L must be numeric "
2671 : 0 : "or LOGICAL", gfc_current_intrinsic_arg[0]->name,
2672 : : gfc_current_intrinsic, &vector_a->where);
2673 : 0 : return false;
2674 : : }
2675 : :
2676 : 171 : if (!rank_check (vector_a, 0, 1))
2677 : : return false;
2678 : :
2679 : 171 : if (!rank_check (vector_b, 1, 1))
2680 : : return false;
2681 : :
2682 : 171 : if (! identical_dimen_shape (vector_a, 0, vector_b, 0))
2683 : : {
2684 : 1 : gfc_error ("Different shape for arguments %qs and %qs at %L for "
2685 : : "intrinsic %<dot_product%>",
2686 : 1 : gfc_current_intrinsic_arg[0]->name,
2687 : 1 : gfc_current_intrinsic_arg[1]->name, &vector_a->where);
2688 : 1 : return false;
2689 : : }
2690 : :
2691 : : return true;
2692 : : }
2693 : :
2694 : :
2695 : : bool
2696 : 22 : gfc_check_dprod (gfc_expr *x, gfc_expr *y)
2697 : : {
2698 : 22 : if (!type_check (x, 0, BT_REAL)
2699 : 22 : || !type_check (y, 1, BT_REAL))
2700 : 0 : return false;
2701 : :
2702 : 22 : if (x->ts.kind != gfc_default_real_kind)
2703 : : {
2704 : 1 : gfc_error ("%qs argument of %qs intrinsic at %L must be default "
2705 : 1 : "real", gfc_current_intrinsic_arg[0]->name,
2706 : : gfc_current_intrinsic, &x->where);
2707 : 1 : return false;
2708 : : }
2709 : :
2710 : 21 : if (y->ts.kind != gfc_default_real_kind)
2711 : : {
2712 : 1 : gfc_error ("%qs argument of %qs intrinsic at %L must be default "
2713 : 1 : "real", gfc_current_intrinsic_arg[1]->name,
2714 : : gfc_current_intrinsic, &y->where);
2715 : 1 : return false;
2716 : : }
2717 : :
2718 : : return true;
2719 : : }
2720 : :
2721 : : bool
2722 : 1548 : gfc_check_dshift (gfc_expr *i, gfc_expr *j, gfc_expr *shift)
2723 : : {
2724 : : /* i and j cannot both be BOZ literal constants. */
2725 : 1548 : if (!boz_args_check (i, j))
2726 : : return false;
2727 : :
2728 : : /* If i is BOZ and j is integer, convert i to type of j. If j is not
2729 : : an integer, clear the BOZ; otherwise, check that i is an integer. */
2730 : 1544 : if (i->ts.type == BT_BOZ)
2731 : : {
2732 : 17 : if (j->ts.type != BT_INTEGER)
2733 : 1 : reset_boz (i);
2734 : 16 : else if (!gfc_boz2int (i, j->ts.kind))
2735 : : return false;
2736 : : }
2737 : 1527 : else if (!type_check (i, 0, BT_INTEGER))
2738 : : {
2739 : 1 : if (j->ts.type == BT_BOZ)
2740 : 1 : reset_boz (j);
2741 : 1 : return false;
2742 : : }
2743 : :
2744 : : /* If j is BOZ and i is integer, convert j to type of i. If i is not
2745 : : an integer, clear the BOZ; otherwise, check that i is an integer. */
2746 : 1543 : if (j->ts.type == BT_BOZ)
2747 : : {
2748 : 14 : if (i->ts.type != BT_INTEGER)
2749 : 0 : reset_boz (j);
2750 : 14 : else if (!gfc_boz2int (j, i->ts.kind))
2751 : : return false;
2752 : : }
2753 : 1529 : else if (!type_check (j, 1, BT_INTEGER))
2754 : : return false;
2755 : :
2756 : 1542 : if (!same_type_check (i, 0, j, 1))
2757 : : return false;
2758 : :
2759 : 1538 : if (!type_check (shift, 2, BT_INTEGER))
2760 : : return false;
2761 : :
2762 : 1538 : if (!nonnegative_check ("SHIFT", shift))
2763 : : return false;
2764 : :
2765 : 1536 : if (!less_than_bitsize1 ("I", i, "SHIFT", shift, true))
2766 : : return false;
2767 : :
2768 : : return true;
2769 : : }
2770 : :
2771 : :
2772 : : bool
2773 : 1110 : gfc_check_eoshift (gfc_expr *array, gfc_expr *shift, gfc_expr *boundary,
2774 : : gfc_expr *dim)
2775 : : {
2776 : 1110 : int d;
2777 : :
2778 : 1110 : if (!array_check (array, 0))
2779 : : return false;
2780 : :
2781 : 1110 : if (!type_check (shift, 1, BT_INTEGER))
2782 : : return false;
2783 : :
2784 : 1108 : if (!dim_check (dim, 3, true))
2785 : : return false;
2786 : :
2787 : 1108 : if (!dim_rank_check (dim, array, false))
2788 : : return false;
2789 : :
2790 : 1108 : if (!dim)
2791 : 446 : d = 1;
2792 : 662 : else if (dim->expr_type == EXPR_CONSTANT)
2793 : 586 : gfc_extract_int (dim, &d);
2794 : : else
2795 : 76 : d = -1;
2796 : :
2797 : 1108 : if (array->rank == 1 || shift->rank == 0)
2798 : : {
2799 : 735 : if (!scalar_check (shift, 1))
2800 : : return false;
2801 : : }
2802 : 373 : else if (shift->rank == array->rank - 1)
2803 : : {
2804 : 372 : if (d > 0)
2805 : : {
2806 : : int i, j;
2807 : 1085 : for (i = 0, j = 0; i < array->rank; i++)
2808 : 757 : if (i != d - 1)
2809 : : {
2810 : 428 : if (!identical_dimen_shape (array, i, shift, j))
2811 : : {
2812 : 1 : gfc_error ("%qs argument of %qs intrinsic at %L has "
2813 : : "invalid shape in dimension %d (%ld/%ld)",
2814 : 1 : gfc_current_intrinsic_arg[1]->name,
2815 : : gfc_current_intrinsic, &shift->where, i + 1,
2816 : 1 : mpz_get_si (array->shape[i]),
2817 : 1 : mpz_get_si (shift->shape[j]));
2818 : 1 : return false;
2819 : : }
2820 : :
2821 : 427 : j += 1;
2822 : : }
2823 : : }
2824 : : }
2825 : : else
2826 : : {
2827 : 1 : gfc_error ("%qs argument of intrinsic %qs at %L of must have rank "
2828 : 1 : "%d or be a scalar", gfc_current_intrinsic_arg[1]->name,
2829 : : gfc_current_intrinsic, &shift->where, array->rank - 1);
2830 : 1 : return false;
2831 : : }
2832 : :
2833 : 1104 : if (boundary != NULL)
2834 : : {
2835 : 615 : if (!same_type_check (array, 0, boundary, 2))
2836 : : return false;
2837 : :
2838 : : /* Reject unequal string lengths and emit a better error message than
2839 : : gfc_check_same_strlen would. */
2840 : 615 : if (array->ts.type == BT_CHARACTER)
2841 : : {
2842 : 250 : ssize_t len_a, len_b;
2843 : :
2844 : 250 : len_a = gfc_var_strlen (array);
2845 : 250 : len_b = gfc_var_strlen (boundary);
2846 : 250 : if (len_a != -1 && len_b != -1 && len_a != len_b)
2847 : : {
2848 : 1 : gfc_error ("%qs must be of same type and kind as %qs at %L in %qs",
2849 : 1 : gfc_current_intrinsic_arg[2]->name,
2850 : 1 : gfc_current_intrinsic_arg[0]->name,
2851 : : &boundary->where, gfc_current_intrinsic);
2852 : 1 : return false;
2853 : : }
2854 : : }
2855 : :
2856 : 614 : if (array->rank == 1 || boundary->rank == 0)
2857 : : {
2858 : 360 : if (!scalar_check (boundary, 2))
2859 : : return false;
2860 : : }
2861 : 254 : else if (boundary->rank == array->rank - 1)
2862 : : {
2863 : 252 : if (d > 0)
2864 : : {
2865 : : int i,j;
2866 : 786 : for (i = 0, j = 0; i < array->rank; i++)
2867 : : {
2868 : 542 : if (i != d - 1)
2869 : : {
2870 : 297 : if (!identical_dimen_shape (array, i, boundary, j))
2871 : : {
2872 : 1 : gfc_error ("%qs argument of %qs intrinsic at %L has "
2873 : : "invalid shape in dimension %d (%ld/%ld)",
2874 : 1 : gfc_current_intrinsic_arg[2]->name,
2875 : : gfc_current_intrinsic, &shift->where, i+1,
2876 : 1 : mpz_get_si (array->shape[i]),
2877 : 1 : mpz_get_si (boundary->shape[j]));
2878 : 1 : return false;
2879 : : }
2880 : 296 : j += 1;
2881 : : }
2882 : : }
2883 : : }
2884 : : }
2885 : : else
2886 : : {
2887 : 2 : gfc_error ("%qs argument of intrinsic %qs at %L of must have "
2888 : : "rank %d or be a scalar",
2889 : 2 : gfc_current_intrinsic_arg[1]->name, gfc_current_intrinsic,
2890 : : &shift->where, array->rank - 1);
2891 : 2 : return false;
2892 : : }
2893 : : }
2894 : : else
2895 : : {
2896 : 489 : switch (array->ts.type)
2897 : : {
2898 : : case BT_INTEGER:
2899 : : case BT_LOGICAL:
2900 : : case BT_REAL:
2901 : : case BT_COMPLEX:
2902 : : case BT_CHARACTER:
2903 : : break;
2904 : :
2905 : 1 : default:
2906 : 1 : gfc_error ("Missing %qs argument to %qs intrinsic at %L for %qs "
2907 : 1 : "of type %qs", gfc_current_intrinsic_arg[2]->name,
2908 : : gfc_current_intrinsic, &array->where,
2909 : 1 : gfc_current_intrinsic_arg[0]->name,
2910 : : gfc_typename (array));
2911 : 1 : return false;
2912 : : }
2913 : : }
2914 : :
2915 : : return true;
2916 : : }
2917 : :
2918 : :
2919 : : bool
2920 : 152 : gfc_check_float (gfc_expr *a)
2921 : : {
2922 : 152 : if (a->ts.type == BT_BOZ)
2923 : : {
2924 : 8 : if (gfc_invalid_boz (G_("BOZ literal constant at %L cannot appear in the"
2925 : : " FLOAT intrinsic subprogram"), &a->where))
2926 : : {
2927 : 1 : reset_boz (a);
2928 : 1 : return false;
2929 : : }
2930 : 7 : if (!gfc_boz2int (a, gfc_default_integer_kind))
2931 : : return false;
2932 : : }
2933 : :
2934 : 151 : if (!type_check (a, 0, BT_INTEGER))
2935 : : return false;
2936 : :
2937 : 151 : if ((a->ts.kind != gfc_default_integer_kind)
2938 : 151 : && !gfc_notify_std (GFC_STD_GNU, "non-default INTEGER "
2939 : : "kind argument to %s intrinsic at %L",
2940 : : gfc_current_intrinsic, &a->where))
2941 : : return false;
2942 : :
2943 : : return true;
2944 : : }
2945 : :
2946 : : /* A single complex argument. */
2947 : :
2948 : : bool
2949 : 727 : gfc_check_fn_c (gfc_expr *a)
2950 : : {
2951 : 727 : if (!type_check (a, 0, BT_COMPLEX))
2952 : : return false;
2953 : :
2954 : : return true;
2955 : : }
2956 : :
2957 : :
2958 : : /* A single real argument. */
2959 : :
2960 : : bool
2961 : 6463 : gfc_check_fn_r (gfc_expr *a)
2962 : : {
2963 : 6463 : if (!type_check (a, 0, BT_REAL))
2964 : : return false;
2965 : :
2966 : : return true;
2967 : : }
2968 : :
2969 : : /* A single double argument. */
2970 : :
2971 : : bool
2972 : 12586 : gfc_check_fn_d (gfc_expr *a)
2973 : : {
2974 : 12586 : if (!double_check (a, 0))
2975 : : return false;
2976 : :
2977 : : return true;
2978 : : }
2979 : :
2980 : : /* A single real or complex argument. */
2981 : :
2982 : : bool
2983 : 1001 : gfc_check_fn_rc (gfc_expr *a)
2984 : : {
2985 : 1001 : if (!real_or_complex_check (a, 0))
2986 : : return false;
2987 : :
2988 : : return true;
2989 : : }
2990 : :
2991 : :
2992 : : bool
2993 : 1560 : gfc_check_fn_rc2008 (gfc_expr *a)
2994 : : {
2995 : 1560 : if (!real_or_complex_check (a, 0))
2996 : : return false;
2997 : :
2998 : 1560 : if (a->ts.type == BT_COMPLEX
2999 : 2210 : && !gfc_notify_std (GFC_STD_F2008, "COMPLEX argument %qs "
3000 : : "of %qs intrinsic at %L",
3001 : 650 : gfc_current_intrinsic_arg[0]->name,
3002 : : gfc_current_intrinsic, &a->where))
3003 : : return false;
3004 : :
3005 : : return true;
3006 : : }
3007 : :
3008 : :
3009 : : bool
3010 : 0 : gfc_check_fnum (gfc_expr *unit)
3011 : : {
3012 : 0 : if (!type_check (unit, 0, BT_INTEGER))
3013 : : return false;
3014 : :
3015 : 0 : if (!scalar_check (unit, 0))
3016 : : return false;
3017 : :
3018 : : return true;
3019 : : }
3020 : :
3021 : :
3022 : : bool
3023 : 5575 : gfc_check_huge (gfc_expr *x)
3024 : : {
3025 : 5575 : if (!int_or_real_check (x, 0))
3026 : : return false;
3027 : :
3028 : : return true;
3029 : : }
3030 : :
3031 : :
3032 : : bool
3033 : 24 : gfc_check_hypot (gfc_expr *x, gfc_expr *y)
3034 : : {
3035 : 24 : if (!type_check (x, 0, BT_REAL))
3036 : : return false;
3037 : 24 : if (!same_type_check (x, 0, y, 1))
3038 : : return false;
3039 : :
3040 : : return true;
3041 : : }
3042 : :
3043 : :
3044 : : /* Check that the single argument is an integer. */
3045 : :
3046 : : bool
3047 : 5808 : gfc_check_i (gfc_expr *i)
3048 : : {
3049 : 5808 : if (!type_check (i, 0, BT_INTEGER))
3050 : : return false;
3051 : :
3052 : : return true;
3053 : : }
3054 : :
3055 : :
3056 : : bool
3057 : 4749 : gfc_check_iand_ieor_ior (gfc_expr *i, gfc_expr *j)
3058 : : {
3059 : : /* i and j cannot both be BOZ literal constants. */
3060 : 4749 : if (!boz_args_check (i, j))
3061 : : return false;
3062 : :
3063 : : /* If i is BOZ and j is integer, convert i to type of j. */
3064 : 25 : if (i->ts.type == BT_BOZ && j->ts.type == BT_INTEGER
3065 : 4770 : && !gfc_boz2int (i, j->ts.kind))
3066 : : return false;
3067 : :
3068 : : /* If j is BOZ and i is integer, convert j to type of i. */
3069 : 37 : if (j->ts.type == BT_BOZ && i->ts.type == BT_INTEGER
3070 : 4782 : && !gfc_boz2int (j, i->ts.kind))
3071 : : return false;
3072 : :
3073 : 4745 : if (!type_check (i, 0, BT_INTEGER))
3074 : : return false;
3075 : :
3076 : 4745 : if (!type_check (j, 1, BT_INTEGER))
3077 : : return false;
3078 : :
3079 : 4745 : if (i->ts.kind != j->ts.kind)
3080 : : {
3081 : 1 : gfc_error ("Arguments of %qs have different kind type parameters "
3082 : : "at %L", gfc_current_intrinsic, &i->where);
3083 : 1 : return false;
3084 : : }
3085 : :
3086 : : return true;
3087 : : }
3088 : :
3089 : :
3090 : : bool
3091 : 53 : gfc_check_ibits (gfc_expr *i, gfc_expr *pos, gfc_expr *len)
3092 : : {
3093 : 53 : if (!type_check (i, 0, BT_INTEGER))
3094 : : return false;
3095 : :
3096 : 53 : if (!type_check (pos, 1, BT_INTEGER))
3097 : : return false;
3098 : :
3099 : 53 : if (!type_check (len, 2, BT_INTEGER))
3100 : : return false;
3101 : :
3102 : 53 : if (!nonnegative_check ("pos", pos))
3103 : : return false;
3104 : :
3105 : 48 : if (!nonnegative_check ("len", len))
3106 : : return false;
3107 : :
3108 : 43 : if (!less_than_bitsize2 ("i", i, "pos", pos, "len", len))
3109 : : return false;
3110 : :
3111 : : return true;
3112 : : }
3113 : :
3114 : :
3115 : : bool
3116 : 8910 : gfc_check_ichar_iachar (gfc_expr *c, gfc_expr *kind)
3117 : : {
3118 : 8910 : int i;
3119 : :
3120 : 8910 : if (!type_check (c, 0, BT_CHARACTER))
3121 : : return false;
3122 : :
3123 : 8910 : if (!kind_check (kind, 1, BT_INTEGER))
3124 : : return false;
3125 : :
3126 : 8910 : if (kind && !gfc_notify_std (GFC_STD_F2003, "%qs intrinsic "
3127 : : "with KIND argument at %L",
3128 : : gfc_current_intrinsic, &kind->where))
3129 : : return false;
3130 : :
3131 : 8910 : if (c->expr_type == EXPR_VARIABLE || c->expr_type == EXPR_SUBSTRING)
3132 : : {
3133 : 1894 : gfc_expr *start;
3134 : 1894 : gfc_expr *end;
3135 : 1894 : gfc_ref *ref;
3136 : :
3137 : : /* Substring references don't have the charlength set. */
3138 : 1894 : ref = c->ref;
3139 : 2001 : while (ref && ref->type != REF_SUBSTRING)
3140 : 107 : ref = ref->next;
3141 : :
3142 : 1894 : gcc_assert (ref == NULL || ref->type == REF_SUBSTRING);
3143 : :
3144 : 1894 : if (!ref)
3145 : : {
3146 : : /* Check that the argument is length one. Non-constant lengths
3147 : : can't be checked here, so assume they are ok. */
3148 : 1691 : if (c->ts.u.cl && c->ts.u.cl->length)
3149 : : {
3150 : : /* If we already have a length for this expression then use it. */
3151 : 1684 : if (c->ts.u.cl->length->expr_type != EXPR_CONSTANT)
3152 : : return true;
3153 : 1684 : i = mpz_get_si (c->ts.u.cl->length->value.integer);
3154 : : }
3155 : : else
3156 : : return true;
3157 : : }
3158 : : else
3159 : : {
3160 : 203 : start = ref->u.ss.start;
3161 : 203 : end = ref->u.ss.end;
3162 : :
3163 : 203 : gcc_assert (start);
3164 : 203 : if (end == NULL || end->expr_type != EXPR_CONSTANT
3165 : 146 : || start->expr_type != EXPR_CONSTANT)
3166 : : return true;
3167 : :
3168 : 146 : i = mpz_get_si (end->value.integer) + 1
3169 : 146 : - mpz_get_si (start->value.integer);
3170 : : }
3171 : : }
3172 : : else
3173 : : return true;
3174 : :
3175 : 1830 : if (i != 1)
3176 : : {
3177 : 8 : gfc_error ("Argument of %s at %L must be of length one",
3178 : : gfc_current_intrinsic, &c->where);
3179 : 8 : return false;
3180 : : }
3181 : :
3182 : : return true;
3183 : : }
3184 : :
3185 : :
3186 : : bool
3187 : 251 : gfc_check_idnint (gfc_expr *a)
3188 : : {
3189 : 251 : if (!double_check (a, 0))
3190 : : return false;
3191 : :
3192 : : return true;
3193 : : }
3194 : :
3195 : :
3196 : : bool
3197 : 599 : gfc_check_index (gfc_expr *string, gfc_expr *substring, gfc_expr *back,
3198 : : gfc_expr *kind)
3199 : : {
3200 : 599 : if (!type_check (string, 0, BT_CHARACTER)
3201 : 599 : || !type_check (substring, 1, BT_CHARACTER))
3202 : 0 : return false;
3203 : :
3204 : 599 : if (back != NULL && !type_check (back, 2, BT_LOGICAL))
3205 : : return false;
3206 : :
3207 : 599 : if (!kind_check (kind, 3, BT_INTEGER))
3208 : : return false;
3209 : 599 : if (kind && !gfc_notify_std (GFC_STD_F2003, "%qs intrinsic "
3210 : : "with KIND argument at %L",
3211 : : gfc_current_intrinsic, &kind->where))
3212 : : return false;
3213 : :
3214 : 599 : if (string->ts.kind != substring->ts.kind)
3215 : : {
3216 : 0 : gfc_error ("%qs argument of %qs intrinsic at %L must be the same "
3217 : 0 : "kind as %qs", gfc_current_intrinsic_arg[1]->name,
3218 : : gfc_current_intrinsic, &substring->where,
3219 : 0 : gfc_current_intrinsic_arg[0]->name);
3220 : 0 : return false;
3221 : : }
3222 : :
3223 : : return true;
3224 : : }
3225 : :
3226 : :
3227 : : bool
3228 : 3625 : gfc_check_int (gfc_expr *x, gfc_expr *kind)
3229 : : {
3230 : : /* BOZ is dealt within simplify_int*. */
3231 : 3625 : if (x->ts.type == BT_BOZ)
3232 : : return true;
3233 : :
3234 : 2097 : if (!numeric_check (x, 0))
3235 : : return false;
3236 : :
3237 : 2097 : if (!kind_check (kind, 1, BT_INTEGER))
3238 : : return false;
3239 : :
3240 : : return true;
3241 : : }
3242 : :
3243 : :
3244 : : bool
3245 : 97 : gfc_check_intconv (gfc_expr *x)
3246 : : {
3247 : 97 : if (strcmp (gfc_current_intrinsic, "short") == 0
3248 : 62 : || strcmp (gfc_current_intrinsic, "long") == 0)
3249 : : {
3250 : 36 : gfc_error ("%qs intrinsic subprogram at %L has been removed. "
3251 : : "Use INT intrinsic subprogram.", gfc_current_intrinsic,
3252 : : &x->where);
3253 : 36 : return false;
3254 : : }
3255 : :
3256 : : /* BOZ is dealt within simplify_int*. */
3257 : 61 : if (x->ts.type == BT_BOZ)
3258 : : return true;
3259 : :
3260 : 61 : if (!numeric_check (x, 0))
3261 : : return false;
3262 : :
3263 : : return true;
3264 : : }
3265 : :
3266 : : bool
3267 : 998 : gfc_check_ishft (gfc_expr *i, gfc_expr *shift)
3268 : : {
3269 : 998 : if (!type_check (i, 0, BT_INTEGER)
3270 : 998 : || !type_check (shift, 1, BT_INTEGER))
3271 : 0 : return false;
3272 : :
3273 : 998 : if (!less_than_bitsize1 ("I", i, NULL, shift, true))
3274 : : return false;
3275 : :
3276 : : return true;
3277 : : }
3278 : :
3279 : :
3280 : : bool
3281 : 856 : gfc_check_ishftc (gfc_expr *i, gfc_expr *shift, gfc_expr *size)
3282 : : {
3283 : 856 : if (!type_check (i, 0, BT_INTEGER)
3284 : 856 : || !type_check (shift, 1, BT_INTEGER))
3285 : 0 : return false;
3286 : :
3287 : 856 : if (size != NULL)
3288 : : {
3289 : 605 : int i2, i3;
3290 : :
3291 : 605 : if (!type_check (size, 2, BT_INTEGER))
3292 : 11 : return false;
3293 : :
3294 : 605 : if (!less_than_bitsize1 ("I", i, "SIZE", size, true))
3295 : : return false;
3296 : :
3297 : 602 : if (size->expr_type == EXPR_CONSTANT)
3298 : : {
3299 : 155 : gfc_extract_int (size, &i3);
3300 : 155 : if (i3 <= 0)
3301 : : {
3302 : 4 : gfc_error ("SIZE at %L must be positive", &size->where);
3303 : 4 : return false;
3304 : : }
3305 : :
3306 : 151 : if (shift->expr_type == EXPR_CONSTANT)
3307 : : {
3308 : 126 : gfc_extract_int (shift, &i2);
3309 : 126 : if (i2 < 0)
3310 : 28 : i2 = -i2;
3311 : :
3312 : 126 : if (i2 > i3)
3313 : : {
3314 : 4 : gfc_error ("The absolute value of SHIFT at %L must be less "
3315 : : "than or equal to SIZE at %L", &shift->where,
3316 : : &size->where);
3317 : 4 : return false;
3318 : : }
3319 : : }
3320 : : }
3321 : : }
3322 : 251 : else if (!less_than_bitsize1 ("I", i, NULL, shift, true))
3323 : : return false;
3324 : :
3325 : : return true;
3326 : : }
3327 : :
3328 : :
3329 : : bool
3330 : 8 : gfc_check_kill (gfc_expr *pid, gfc_expr *sig)
3331 : : {
3332 : 8 : if (!type_check (pid, 0, BT_INTEGER))
3333 : : return false;
3334 : :
3335 : 8 : if (!scalar_check (pid, 0))
3336 : : return false;
3337 : :
3338 : 8 : if (!type_check (sig, 1, BT_INTEGER))
3339 : : return false;
3340 : :
3341 : 8 : if (!scalar_check (sig, 1))
3342 : : return false;
3343 : :
3344 : : return true;
3345 : : }
3346 : :
3347 : :
3348 : : bool
3349 : 18 : gfc_check_kill_sub (gfc_expr *pid, gfc_expr *sig, gfc_expr *status)
3350 : : {
3351 : 18 : if (!type_check (pid, 0, BT_INTEGER))
3352 : : return false;
3353 : :
3354 : 18 : if (!scalar_check (pid, 0))
3355 : : return false;
3356 : :
3357 : 18 : if (!type_check (sig, 1, BT_INTEGER))
3358 : : return false;
3359 : :
3360 : 18 : if (!scalar_check (sig, 1))
3361 : : return false;
3362 : :
3363 : 18 : if (status)
3364 : : {
3365 : 13 : if (!type_check (status, 2, BT_INTEGER))
3366 : : return false;
3367 : :
3368 : 13 : if (!scalar_check (status, 2))
3369 : : return false;
3370 : :
3371 : 13 : if (status->expr_type != EXPR_VARIABLE)
3372 : : {
3373 : 1 : gfc_error ("STATUS at %L shall be an INTENT(OUT) variable",
3374 : : &status->where);
3375 : 1 : return false;
3376 : : }
3377 : :
3378 : 12 : if (status->expr_type == EXPR_VARIABLE
3379 : 12 : && status->symtree && status->symtree->n.sym
3380 : 12 : && status->symtree->n.sym->attr.intent == INTENT_IN)
3381 : : {
3382 : 1 : gfc_error ("%qs at %L shall be an INTENT(OUT) variable",
3383 : : status->symtree->name, &status->where);
3384 : 1 : return false;
3385 : : }
3386 : : }
3387 : :
3388 : : return true;
3389 : : }
3390 : :
3391 : :
3392 : : bool
3393 : 4469 : gfc_check_kind (gfc_expr *x)
3394 : : {
3395 : 4469 : if (gfc_invalid_null_arg (x))
3396 : : return false;
3397 : :
3398 : 4468 : if (gfc_bt_struct (x->ts.type) || x->ts.type == BT_CLASS)
3399 : : {
3400 : 2 : gfc_error ("%qs argument of %qs intrinsic at %L must be of "
3401 : 2 : "intrinsic type", gfc_current_intrinsic_arg[0]->name,
3402 : : gfc_current_intrinsic, &x->where);
3403 : 2 : return false;
3404 : : }
3405 : 4466 : if (x->ts.type == BT_PROCEDURE)
3406 : : {
3407 : 2 : gfc_error ("%qs argument of %qs intrinsic at %L must be a data entity",
3408 : 2 : gfc_current_intrinsic_arg[0]->name, gfc_current_intrinsic,
3409 : : &x->where);
3410 : 2 : return false;
3411 : : }
3412 : :
3413 : : return true;
3414 : : }
3415 : :
3416 : :
3417 : : bool
3418 : 6314 : gfc_check_lbound (gfc_expr *array, gfc_expr *dim, gfc_expr *kind)
3419 : : {
3420 : 6314 : if (!array_check (array, 0))
3421 : : return false;
3422 : :
3423 : 6313 : if (!dim_check (dim, 1, false))
3424 : : return false;
3425 : :
3426 : 6313 : if (!dim_rank_check (dim, array, 1))
3427 : : return false;
3428 : :
3429 : 6313 : if (!kind_check (kind, 2, BT_INTEGER))
3430 : : return false;
3431 : 6313 : if (kind && !gfc_notify_std (GFC_STD_F2003, "%qs intrinsic "
3432 : : "with KIND argument at %L",
3433 : : gfc_current_intrinsic, &kind->where))
3434 : : return false;
3435 : :
3436 : : return true;
3437 : : }
3438 : :
3439 : :
3440 : : bool
3441 : 297 : gfc_check_lcobound (gfc_expr *coarray, gfc_expr *dim, gfc_expr *kind)
3442 : : {
3443 : 297 : if (flag_coarray == GFC_FCOARRAY_NONE)
3444 : : {
3445 : 0 : gfc_fatal_error ("Coarrays disabled at %C, use %<-fcoarray=%> to enable");
3446 : : return false;
3447 : : }
3448 : :
3449 : 297 : if (!coarray_check (coarray, 0))
3450 : : return false;
3451 : :
3452 : 293 : if (dim != NULL)
3453 : : {
3454 : 168 : if (!dim_check (dim, 1, false))
3455 : : return false;
3456 : :
3457 : 168 : if (!dim_corank_check (dim, coarray))
3458 : : return false;
3459 : : }
3460 : :
3461 : 293 : if (!kind_check (kind, 2, BT_INTEGER))
3462 : : return false;
3463 : :
3464 : : return true;
3465 : : }
3466 : :
3467 : :
3468 : : bool
3469 : 9818 : gfc_check_len_lentrim (gfc_expr *s, gfc_expr *kind)
3470 : : {
3471 : 9818 : if (!type_check (s, 0, BT_CHARACTER))
3472 : : return false;
3473 : :
3474 : 9798 : if (gfc_invalid_null_arg (s))
3475 : : return false;
3476 : :
3477 : 9792 : if (!kind_check (kind, 1, BT_INTEGER))
3478 : : return false;
3479 : 9792 : if (kind && !gfc_notify_std (GFC_STD_F2003, "%qs intrinsic "
3480 : : "with KIND argument at %L",
3481 : : gfc_current_intrinsic, &kind->where))
3482 : : return false;
3483 : :
3484 : : return true;
3485 : : }
3486 : :
3487 : :
3488 : : bool
3489 : 187 : gfc_check_lge_lgt_lle_llt (gfc_expr *a, gfc_expr *b)
3490 : : {
3491 : 187 : if (!type_check (a, 0, BT_CHARACTER))
3492 : : return false;
3493 : 187 : if (!kind_value_check (a, 0, gfc_default_character_kind))
3494 : : return false;
3495 : :
3496 : 155 : if (!type_check (b, 1, BT_CHARACTER))
3497 : : return false;
3498 : 155 : if (!kind_value_check (b, 1, gfc_default_character_kind))
3499 : : return false;
3500 : :
3501 : : return true;
3502 : : }
3503 : :
3504 : :
3505 : : bool
3506 : 7 : gfc_check_link (gfc_expr *path1, gfc_expr *path2)
3507 : : {
3508 : 7 : if (!type_check (path1, 0, BT_CHARACTER))
3509 : : return false;
3510 : 7 : if (!kind_value_check (path1, 0, gfc_default_character_kind))
3511 : : return false;
3512 : :
3513 : 5 : if (!type_check (path2, 1, BT_CHARACTER))
3514 : : return false;
3515 : 5 : if (!kind_value_check (path2, 1, gfc_default_character_kind))
3516 : : return false;
3517 : :
3518 : : return true;
3519 : : }
3520 : :
3521 : :
3522 : : bool
3523 : 15 : gfc_check_link_sub (gfc_expr *path1, gfc_expr *path2, gfc_expr *status)
3524 : : {
3525 : 15 : if (!type_check (path1, 0, BT_CHARACTER))
3526 : : return false;
3527 : 15 : if (!kind_value_check (path1, 0, gfc_default_character_kind))
3528 : : return false;
3529 : :
3530 : 11 : if (!type_check (path2, 1, BT_CHARACTER))
3531 : : return false;
3532 : 11 : if (!kind_value_check (path2, 0, gfc_default_character_kind))
3533 : : return false;
3534 : :
3535 : 9 : if (status == NULL)
3536 : : return true;
3537 : :
3538 : 7 : if (!type_check (status, 2, BT_INTEGER))
3539 : : return false;
3540 : :
3541 : 7 : if (!scalar_check (status, 2))
3542 : : return false;
3543 : :
3544 : : return true;
3545 : : }
3546 : :
3547 : :
3548 : : bool
3549 : 3853 : gfc_check_loc (gfc_expr *expr)
3550 : : {
3551 : 3853 : return variable_check (expr, 0, true);
3552 : : }
3553 : :
3554 : :
3555 : : bool
3556 : 7 : gfc_check_symlnk (gfc_expr *path1, gfc_expr *path2)
3557 : : {
3558 : 7 : if (!type_check (path1, 0, BT_CHARACTER))
3559 : : return false;
3560 : 7 : if (!kind_value_check (path1, 0, gfc_default_character_kind))
3561 : : return false;
3562 : :
3563 : 5 : if (!type_check (path2, 1, BT_CHARACTER))
3564 : : return false;
3565 : 5 : if (!kind_value_check (path2, 1, gfc_default_character_kind))
3566 : : return false;
3567 : :
3568 : : return true;
3569 : : }
3570 : :
3571 : :
3572 : : bool
3573 : 15 : gfc_check_symlnk_sub (gfc_expr *path1, gfc_expr *path2, gfc_expr *status)
3574 : : {
3575 : 15 : if (!type_check (path1, 0, BT_CHARACTER))
3576 : : return false;
3577 : 15 : if (!kind_value_check (path1, 0, gfc_default_character_kind))
3578 : : return false;
3579 : :
3580 : 11 : if (!type_check (path2, 1, BT_CHARACTER))
3581 : : return false;
3582 : 11 : if (!kind_value_check (path2, 1, gfc_default_character_kind))
3583 : : return false;
3584 : :
3585 : 9 : if (status == NULL)
3586 : : return true;
3587 : :
3588 : 7 : if (!type_check (status, 2, BT_INTEGER))
3589 : : return false;
3590 : :
3591 : 7 : if (!scalar_check (status, 2))
3592 : : return false;
3593 : :
3594 : : return true;
3595 : : }
3596 : :
3597 : :
3598 : : bool
3599 : 28 : gfc_check_logical (gfc_expr *a, gfc_expr *kind)
3600 : : {
3601 : 28 : if (!type_check (a, 0, BT_LOGICAL))
3602 : : return false;
3603 : 28 : if (!kind_check (kind, 1, BT_LOGICAL))
3604 : : return false;
3605 : :
3606 : : return true;
3607 : : }
3608 : :
3609 : :
3610 : : /* Min/max family. */
3611 : :
3612 : : static bool
3613 : 4742 : min_max_args (gfc_actual_arglist *args)
3614 : : {
3615 : 4742 : gfc_actual_arglist *arg;
3616 : 4742 : int i, j, nargs, *nlabels, nlabelless;
3617 : 4742 : bool a1 = false, a2 = false;
3618 : :
3619 : 4742 : if (args == NULL || args->next == NULL)
3620 : : {
3621 : 0 : gfc_error ("Intrinsic %qs at %L must have at least two arguments",
3622 : : gfc_current_intrinsic, gfc_current_intrinsic_where);
3623 : 0 : return false;
3624 : : }
3625 : :
3626 : 4742 : if (!args->name)
3627 : 4730 : a1 = true;
3628 : :
3629 : 4742 : if (!args->next->name)
3630 : 4729 : a2 = true;
3631 : :
3632 : 4742 : nargs = 0;
3633 : 15709 : for (arg = args; arg; arg = arg->next)
3634 : 10967 : if (arg->name)
3635 : 38 : nargs++;
3636 : :
3637 : 4742 : if (nargs == 0)
3638 : : return true;
3639 : :
3640 : : /* Note: Having a keywordless argument after an "arg=" is checked before. */
3641 : 13 : nlabelless = 0;
3642 : 13 : nlabels = XALLOCAVEC (int, nargs);
3643 : 40 : for (arg = args, i = 0; arg; arg = arg->next, i++)
3644 : 34 : if (arg->name)
3645 : : {
3646 : 33 : int n;
3647 : 33 : char *endp;
3648 : :
3649 : 33 : if (arg->name[0] != 'a' || arg->name[1] < '1' || arg->name[1] > '9')
3650 : 2 : goto unknown;
3651 : 31 : n = strtol (&arg->name[1], &endp, 10);
3652 : 31 : if (endp[0] != '\0')
3653 : 4 : goto unknown;
3654 : 27 : if (n <= 0)
3655 : 0 : goto unknown;
3656 : 27 : if (n <= nlabelless)
3657 : 1 : goto duplicate;
3658 : 26 : nlabels[i] = n;
3659 : 26 : if (n == 1)
3660 : : a1 = true;
3661 : 15 : if (n == 2)
3662 : 5 : a2 = true;
3663 : : }
3664 : : else
3665 : 1 : nlabelless++;
3666 : :
3667 : 6 : if (!a1 || !a2)
3668 : : {
3669 : 4 : gfc_error ("Missing %qs argument to the %s intrinsic at %L",
3670 : : !a1 ? "a1" : "a2", gfc_current_intrinsic,
3671 : : gfc_current_intrinsic_where);
3672 : 4 : return false;
3673 : : }
3674 : :
3675 : : /* Check for duplicates. */
3676 : 8 : for (i = 0; i < nargs; i++)
3677 : 12 : for (j = i + 1; j < nargs; j++)
3678 : 6 : if (nlabels[i] == nlabels[j])
3679 : 0 : goto duplicate;
3680 : :
3681 : : return true;
3682 : :
3683 : 1 : duplicate:
3684 : 1 : gfc_error ("Duplicate argument %qs at %L to intrinsic %s", arg->name,
3685 : 1 : &arg->expr->where, gfc_current_intrinsic);
3686 : 1 : return false;
3687 : :
3688 : 6 : unknown:
3689 : 6 : gfc_error ("Unknown argument %qs at %L to intrinsic %s", arg->name,
3690 : 6 : &arg->expr->where, gfc_current_intrinsic);
3691 : 6 : return false;
3692 : : }
3693 : :
3694 : :
3695 : : static bool
3696 : 2419 : check_rest (bt type, int kind, gfc_actual_arglist *arglist)
3697 : : {
3698 : 2419 : gfc_actual_arglist *arg, *tmp;
3699 : 2419 : gfc_expr *x;
3700 : 2419 : int m, n;
3701 : :
3702 : 2419 : if (!min_max_args (arglist))
3703 : : return false;
3704 : :
3705 : 7933 : for (arg = arglist, n=1; arg; arg = arg->next, n++)
3706 : : {
3707 : 5561 : x = arg->expr;
3708 : 5561 : if (x->ts.type != type || x->ts.kind != kind)
3709 : : {
3710 : 163 : if (x->ts.type == type)
3711 : : {
3712 : 163 : if (x->ts.type == BT_CHARACTER)
3713 : : {
3714 : 2 : gfc_error ("Different character kinds at %L", &x->where);
3715 : 2 : return false;
3716 : : }
3717 : 161 : if (!gfc_notify_std (GFC_STD_GNU, "Different type "
3718 : : "kinds at %L", &x->where))
3719 : : return false;
3720 : : }
3721 : : else
3722 : : {
3723 : 0 : gfc_error ("%<a%d%> argument of %qs intrinsic at %L must be "
3724 : : "%s(%d)", n, gfc_current_intrinsic, &x->where,
3725 : : gfc_basic_typename (type), kind);
3726 : 0 : return false;
3727 : : }
3728 : : }
3729 : :
3730 : 9695 : for (tmp = arglist, m=1; tmp != arg; tmp = tmp->next, m++)
3731 : 4172 : if (!gfc_check_conformance (tmp->expr, x,
3732 : 4172 : _("arguments 'a%d' and 'a%d' for "
3733 : : "intrinsic '%s'"), m, n,
3734 : : gfc_current_intrinsic))
3735 : : return false;
3736 : : }
3737 : :
3738 : : return true;
3739 : : }
3740 : :
3741 : :
3742 : : bool
3743 : 2323 : gfc_check_min_max (gfc_actual_arglist *arg)
3744 : : {
3745 : 2323 : gfc_expr *x;
3746 : :
3747 : 2323 : if (!min_max_args (arg))
3748 : : return false;
3749 : :
3750 : 2321 : x = arg->expr;
3751 : :
3752 : 2321 : if (x->ts.type == BT_CHARACTER)
3753 : : {
3754 : 521 : if (!gfc_notify_std (GFC_STD_F2003, "%qs intrinsic "
3755 : : "with CHARACTER argument at %L",
3756 : : gfc_current_intrinsic, &x->where))
3757 : : return false;
3758 : : }
3759 : 1800 : else if (x->ts.type != BT_INTEGER && x->ts.type != BT_REAL)
3760 : : {
3761 : 0 : gfc_error ("%<a1%> argument of %qs intrinsic at %L must be INTEGER, "
3762 : : "REAL or CHARACTER", gfc_current_intrinsic, &x->where);
3763 : 0 : return false;
3764 : : }
3765 : :
3766 : 2320 : return check_rest (x->ts.type, x->ts.kind, arg);
3767 : : }
3768 : :
3769 : :
3770 : : bool
3771 : 41 : gfc_check_min_max_integer (gfc_actual_arglist *arg)
3772 : : {
3773 : 41 : return check_rest (BT_INTEGER, gfc_default_integer_kind, arg);
3774 : : }
3775 : :
3776 : :
3777 : : bool
3778 : 48 : gfc_check_min_max_real (gfc_actual_arglist *arg)
3779 : : {
3780 : 48 : return check_rest (BT_REAL, gfc_default_real_kind, arg);
3781 : : }
3782 : :
3783 : :
3784 : : bool
3785 : 10 : gfc_check_min_max_double (gfc_actual_arglist *arg)
3786 : : {
3787 : 10 : return check_rest (BT_REAL, gfc_default_double_kind, arg);
3788 : : }
3789 : :
3790 : :
3791 : : /* End of min/max family. */
3792 : :
3793 : : bool
3794 : 16 : gfc_check_malloc (gfc_expr *size)
3795 : : {
3796 : 16 : if (!type_check (size, 0, BT_INTEGER))
3797 : : return false;
3798 : :
3799 : 16 : if (!scalar_check (size, 0))
3800 : : return false;
3801 : :
3802 : : return true;
3803 : : }
3804 : :
3805 : :
3806 : : bool
3807 : 1001 : gfc_check_matmul (gfc_expr *matrix_a, gfc_expr *matrix_b)
3808 : : {
3809 : 1001 : if ((matrix_a->ts.type != BT_LOGICAL) && !gfc_numeric_ts (&matrix_a->ts))
3810 : : {
3811 : 3 : gfc_error ("%qs argument of %qs intrinsic at %L must be numeric "
3812 : 3 : "or LOGICAL", gfc_current_intrinsic_arg[0]->name,
3813 : : gfc_current_intrinsic, &matrix_a->where);
3814 : 3 : return false;
3815 : : }
3816 : :
3817 : 998 : if ((matrix_b->ts.type != BT_LOGICAL) && !gfc_numeric_ts (&matrix_b->ts))
3818 : : {
3819 : 2 : gfc_error ("%qs argument of %qs intrinsic at %L must be numeric "
3820 : 2 : "or LOGICAL", gfc_current_intrinsic_arg[1]->name,
3821 : : gfc_current_intrinsic, &matrix_b->where);
3822 : 2 : return false;
3823 : : }
3824 : :
3825 : 20 : if ((matrix_a->ts.type == BT_LOGICAL && gfc_numeric_ts (&matrix_b->ts))
3826 : 1015 : || (gfc_numeric_ts (&matrix_a->ts) && matrix_b->ts.type == BT_LOGICAL))
3827 : : {
3828 : 2 : gfc_error ("Argument types of %qs intrinsic at %L must match (%s/%s)",
3829 : : gfc_current_intrinsic, &matrix_a->where,
3830 : : gfc_typename(&matrix_a->ts), gfc_typename(&matrix_b->ts));
3831 : 2 : return false;
3832 : : }
3833 : :
3834 : 994 : switch (matrix_a->rank)
3835 : : {
3836 : 145 : case 1:
3837 : 145 : if (!rank_check (matrix_b, 1, 2))
3838 : : return false;
3839 : : /* Check for case matrix_a has shape(m), matrix_b has shape (m, k). */
3840 : 145 : if (!identical_dimen_shape (matrix_a, 0, matrix_b, 0))
3841 : : {
3842 : 2 : gfc_error ("Different shape on dimension 1 for arguments %qs "
3843 : : "and %qs at %L for intrinsic matmul",
3844 : 2 : gfc_current_intrinsic_arg[0]->name,
3845 : 2 : gfc_current_intrinsic_arg[1]->name, &matrix_a->where);
3846 : 2 : return false;
3847 : : }
3848 : : break;
3849 : :
3850 : 849 : case 2:
3851 : 849 : if (matrix_b->rank != 2)
3852 : : {
3853 : 176 : if (!rank_check (matrix_b, 1, 1))
3854 : : return false;
3855 : : }
3856 : : /* matrix_b has rank 1 or 2 here. Common check for the cases
3857 : : - matrix_a has shape (n,m) and matrix_b has shape (m, k)
3858 : : - matrix_a has shape (n,m) and matrix_b has shape (m). */
3859 : 849 : if (!identical_dimen_shape (matrix_a, 1, matrix_b, 0))
3860 : : {
3861 : 0 : gfc_error ("Different shape on dimension 2 for argument %qs and "
3862 : : "dimension 1 for argument %qs at %L for intrinsic "
3863 : 0 : "matmul", gfc_current_intrinsic_arg[0]->name,
3864 : 0 : gfc_current_intrinsic_arg[1]->name, &matrix_a->where);
3865 : 0 : return false;
3866 : : }
3867 : : break;
3868 : :
3869 : 0 : default:
3870 : 0 : gfc_error ("%qs argument of %qs intrinsic at %L must be of rank "
3871 : 0 : "1 or 2", gfc_current_intrinsic_arg[0]->name,
3872 : : gfc_current_intrinsic, &matrix_a->where);
3873 : 0 : return false;
3874 : : }
3875 : :
3876 : : return true;
3877 : : }
3878 : :
3879 : :
3880 : : /* Whoever came up with this interface was probably on something.
3881 : : The possibilities for the occupation of the second and third
3882 : : parameters are:
3883 : :
3884 : : Arg #2 Arg #3
3885 : : NULL NULL
3886 : : DIM NULL
3887 : : MASK NULL
3888 : : NULL MASK minloc(array, mask=m)
3889 : : DIM MASK
3890 : :
3891 : : I.e. in the case of minloc(array,mask), mask will be in the second
3892 : : position of the argument list and we'll have to fix that up. Also,
3893 : : add the BACK argument if that isn't present. */
3894 : :
3895 : : bool
3896 : 6653 : gfc_check_minloc_maxloc (gfc_actual_arglist *ap)
3897 : : {
3898 : 6653 : gfc_expr *a, *m, *d, *k, *b;
3899 : :
3900 : 6653 : a = ap->expr;
3901 : 6653 : if (!int_or_real_or_char_check_f2003 (a, 0) || !array_check (a, 0))
3902 : 0 : return false;
3903 : :
3904 : 6653 : d = ap->next->expr;
3905 : 6653 : m = ap->next->next->expr;
3906 : 6653 : k = ap->next->next->next->expr;
3907 : 6653 : b = ap->next->next->next->next->expr;
3908 : :
3909 : 6653 : if (b)
3910 : : {
3911 : 64 : if (!type_check (b, 4, BT_LOGICAL) || !scalar_check (b,4))
3912 : 4 : return false;
3913 : : }
3914 : : else
3915 : : {
3916 : 6589 : b = gfc_get_logical_expr (gfc_logical_4_kind, NULL, 0);
3917 : 6589 : ap->next->next->next->next->expr = b;
3918 : 6589 : ap->next->next->next->next->name = gfc_get_string ("back");
3919 : : }
3920 : :
3921 : 6649 : if (m == NULL && d != NULL && d->ts.type == BT_LOGICAL
3922 : 62 : && ap->next->name == NULL)
3923 : : {
3924 : 62 : m = d;
3925 : 62 : d = NULL;
3926 : 62 : ap->next->expr = NULL;
3927 : 62 : ap->next->next->expr = m;
3928 : : }
3929 : :
3930 : 6649 : if (!dim_check (d, 1, false))
3931 : : return false;
3932 : :
3933 : 6649 : if (!dim_rank_check (d, a, 0))
3934 : : return false;
3935 : :
3936 : 6648 : if (m != NULL && !type_check (m, 2, BT_LOGICAL))
3937 : : return false;
3938 : :
3939 : 6644 : if (m != NULL
3940 : 11436 : && !gfc_check_conformance (a, m,
3941 : 4792 : _("arguments '%s' and '%s' for intrinsic %s"),
3942 : 4792 : gfc_current_intrinsic_arg[0]->name,
3943 : 4792 : gfc_current_intrinsic_arg[2]->name,
3944 : : gfc_current_intrinsic))
3945 : : return false;
3946 : :
3947 : 6636 : if (!kind_check (k, 1, BT_INTEGER))
3948 : : return false;
3949 : :
3950 : : return true;
3951 : : }
3952 : :
3953 : : /* Check function for findloc. Mostly like gfc_check_minloc_maxloc
3954 : : above, with the additional "value" argument. */
3955 : :
3956 : : bool
3957 : 733 : gfc_check_findloc (gfc_actual_arglist *ap)
3958 : : {
3959 : 733 : gfc_expr *a, *v, *m, *d, *k, *b;
3960 : 733 : bool a1, v1;
3961 : :
3962 : 733 : a = ap->expr;
3963 : 733 : if (!intrinsic_type_check (a, 0) || !array_check (a, 0))
3964 : 0 : return false;
3965 : :
3966 : 733 : v = ap->next->expr;
3967 : 733 : if (!intrinsic_type_check (v, 1) || !scalar_check (v,1))
3968 : 1 : return false;
3969 : :
3970 : : /* Check if the type are both logical. */
3971 : 732 : a1 = a->ts.type == BT_LOGICAL;
3972 : 732 : v1 = v->ts.type == BT_LOGICAL;
3973 : 732 : if ((a1 && !v1) || (!a1 && v1))
3974 : 1 : goto incompat;
3975 : :
3976 : : /* Check if the type are both character. */
3977 : 731 : a1 = a->ts.type == BT_CHARACTER;
3978 : 731 : v1 = v->ts.type == BT_CHARACTER;
3979 : 731 : if ((a1 && !v1) || (!a1 && v1))
3980 : 2 : goto incompat;
3981 : :
3982 : : /* Check the kind of the characters argument match. */
3983 : 729 : if (a1 && v1 && a->ts.kind != v->ts.kind)
3984 : 4 : goto incompat;
3985 : :
3986 : 725 : d = ap->next->next->expr;
3987 : 725 : m = ap->next->next->next->expr;
3988 : 725 : k = ap->next->next->next->next->expr;
3989 : 725 : b = ap->next->next->next->next->next->expr;
3990 : :
3991 : 725 : if (b)
3992 : : {
3993 : 176 : if (!type_check (b, 5, BT_LOGICAL) || !scalar_check (b,4))
3994 : 0 : return false;
3995 : : }
3996 : : else
3997 : : {
3998 : 549 : b = gfc_get_logical_expr (gfc_logical_4_kind, NULL, 0);
3999 : 549 : ap->next->next->next->next->next->expr = b;
4000 : 549 : ap->next->next->next->next->next->name = gfc_get_string ("back");
4001 : : }
4002 : :
4003 : 725 : if (m == NULL && d != NULL && d->ts.type == BT_LOGICAL
4004 : 13 : && ap->next->name == NULL)
4005 : : {
4006 : 13 : m = d;
4007 : 13 : d = NULL;
4008 : 13 : ap->next->next->expr = NULL;
4009 : 13 : ap->next->next->next->expr = m;
4010 : : }
4011 : :
4012 : 725 : if (!dim_check (d, 2, false))
4013 : : return false;
4014 : :
4015 : 724 : if (!dim_rank_check (d, a, 0))
4016 : : return false;
4017 : :
4018 : 723 : if (m != NULL && !type_check (m, 3, BT_LOGICAL))
4019 : : return false;
4020 : :
4021 : 721 : if (m != NULL
4022 : 1097 : && !gfc_check_conformance (a, m,
4023 : 376 : _("arguments '%s' and '%s' for intrinsic %s"),
4024 : 376 : gfc_current_intrinsic_arg[0]->name,
4025 : 376 : gfc_current_intrinsic_arg[3]->name,
4026 : : gfc_current_intrinsic))
4027 : : return false;
4028 : :
4029 : 720 : if (!kind_check (k, 1, BT_INTEGER))
4030 : : return false;
4031 : :
4032 : : return true;
4033 : :
4034 : 7 : incompat:
4035 : 7 : gfc_error ("Argument %qs of %qs intrinsic at %L must be in type "
4036 : : "conformance to argument %qs at %L",
4037 : 7 : gfc_current_intrinsic_arg[0]->name,
4038 : : gfc_current_intrinsic, &a->where,
4039 : 7 : gfc_current_intrinsic_arg[1]->name, &v->where);
4040 : 7 : return false;
4041 : : }
4042 : :
4043 : :
4044 : : /* Similar to minloc/maxloc, the argument list might need to be
4045 : : reordered for the MINVAL, MAXVAL, PRODUCT, and SUM intrinsics. The
4046 : : difference is that MINLOC/MAXLOC take an additional KIND argument.
4047 : : The possibilities are:
4048 : :
4049 : : Arg #2 Arg #3
4050 : : NULL NULL
4051 : : DIM NULL
4052 : : MASK NULL
4053 : : NULL MASK minval(array, mask=m)
4054 : : DIM MASK
4055 : :
4056 : : I.e. in the case of minval(array,mask), mask will be in the second
4057 : : position of the argument list and we'll have to fix that up. */
4058 : :
4059 : : static bool
4060 : 6970 : check_reduction (gfc_actual_arglist *ap)
4061 : : {
4062 : 6970 : gfc_expr *a, *m, *d;
4063 : :
4064 : 6970 : a = ap->expr;
4065 : 6970 : d = ap->next->expr;
4066 : 6970 : m = ap->next->next->expr;
4067 : :
4068 : 6970 : if (m == NULL && d != NULL && d->ts.type == BT_LOGICAL
4069 : 254 : && ap->next->name == NULL)
4070 : : {
4071 : 254 : m = d;
4072 : 254 : d = NULL;
4073 : 254 : ap->next->expr = NULL;
4074 : 254 : ap->next->next->expr = m;
4075 : : }
4076 : :
4077 : 6970 : if (!dim_check (d, 1, false))
4078 : : return false;
4079 : :
4080 : 6970 : if (!dim_rank_check (d, a, 0))
4081 : : return false;
4082 : :
4083 : 6967 : if (m != NULL && !type_check (m, 2, BT_LOGICAL))
4084 : : return false;
4085 : :
4086 : 6967 : if (m != NULL
4087 : 10326 : && !gfc_check_conformance (a, m,
4088 : 3359 : _("arguments '%s' and '%s' for intrinsic %s"),
4089 : 3359 : gfc_current_intrinsic_arg[0]->name,
4090 : 3359 : gfc_current_intrinsic_arg[2]->name,
4091 : : gfc_current_intrinsic))
4092 : : return false;
4093 : :
4094 : : return true;
4095 : : }
4096 : :
4097 : :
4098 : : bool
4099 : 3880 : gfc_check_minval_maxval (gfc_actual_arglist *ap)
4100 : : {
4101 : 3880 : if (!int_or_real_or_char_check_f2003 (ap->expr, 0)
4102 : 3880 : || !array_check (ap->expr, 0))
4103 : 0 : return false;
4104 : :
4105 : 3880 : return check_reduction (ap);
4106 : : }
4107 : :
4108 : :
4109 : : bool
4110 : 2667 : gfc_check_product_sum (gfc_actual_arglist *ap)
4111 : : {
4112 : 2667 : if (!numeric_check (ap->expr, 0)
4113 : 2667 : || !array_check (ap->expr, 0))
4114 : 0 : return false;
4115 : :
4116 : 2667 : return check_reduction (ap);
4117 : : }
4118 : :
4119 : :
4120 : : /* For IANY, IALL and IPARITY. */
4121 : :
4122 : : bool
4123 : 924 : gfc_check_mask (gfc_expr *i, gfc_expr *kind)
4124 : : {
4125 : 924 : int k;
4126 : :
4127 : 924 : if (!type_check (i, 0, BT_INTEGER))
4128 : : return false;
4129 : :
4130 : 924 : if (!nonnegative_check ("I", i))
4131 : : return false;
4132 : :
4133 : 922 : if (!kind_check (kind, 1, BT_INTEGER))
4134 : : return false;
4135 : :
4136 : 922 : if (kind)
4137 : 912 : gfc_extract_int (kind, &k);
4138 : : else
4139 : 10 : k = gfc_default_integer_kind;
4140 : :
4141 : 922 : if (!less_than_bitsizekind ("I", i, k))
4142 : : return false;
4143 : :
4144 : : return true;
4145 : : }
4146 : :
4147 : :
4148 : : bool
4149 : 423 : gfc_check_transf_bit_intrins (gfc_actual_arglist *ap)
4150 : : {
4151 : 423 : if (ap->expr->ts.type != BT_INTEGER)
4152 : : {
4153 : 0 : gfc_error ("%qs argument of %qs intrinsic at %L must be INTEGER",
4154 : 0 : gfc_current_intrinsic_arg[0]->name,
4155 : : gfc_current_intrinsic, &ap->expr->where);
4156 : 0 : return false;
4157 : : }
4158 : :
4159 : 423 : if (!array_check (ap->expr, 0))
4160 : : return false;
4161 : :
4162 : 423 : return check_reduction (ap);
4163 : : }
4164 : :
4165 : :
4166 : : bool
4167 : 1438 : gfc_check_merge (gfc_expr *tsource, gfc_expr *fsource, gfc_expr *mask)
4168 : : {
4169 : 1438 : if (gfc_invalid_null_arg (tsource))
4170 : : return false;
4171 : :
4172 : 1436 : if (gfc_invalid_null_arg (fsource))
4173 : : return false;
4174 : :
4175 : 1435 : if (!same_type_check (tsource, 0, fsource, 1))
4176 : : return false;
4177 : :
4178 : 1435 : if (!type_check (mask, 2, BT_LOGICAL))
4179 : : return false;
4180 : :
4181 : 1435 : if (tsource->ts.type == BT_CHARACTER)
4182 : 571 : return gfc_check_same_strlen (tsource, fsource, "MERGE intrinsic");
4183 : :
4184 : : return true;
4185 : : }
4186 : :
4187 : :
4188 : : bool
4189 : 313 : gfc_check_merge_bits (gfc_expr *i, gfc_expr *j, gfc_expr *mask)
4190 : : {
4191 : : /* i and j cannot both be BOZ literal constants. */
4192 : 313 : if (!boz_args_check (i, j))
4193 : : return false;
4194 : :
4195 : : /* If i is BOZ and j is integer, convert i to type of j. */
4196 : 12 : if (i->ts.type == BT_BOZ && j->ts.type == BT_INTEGER
4197 : 324 : && !gfc_boz2int (i, j->ts.kind))
4198 : : return false;
4199 : :
4200 : : /* If j is BOZ and i is integer, convert j to type of i. */
4201 : 24 : if (j->ts.type == BT_BOZ && i->ts.type == BT_INTEGER
4202 : 336 : && !gfc_boz2int (j, i->ts.kind))
4203 : : return false;
4204 : :
4205 : 312 : if (!type_check (i, 0, BT_INTEGER))
4206 : : return false;
4207 : :
4208 : 312 : if (!type_check (j, 1, BT_INTEGER))
4209 : : return false;
4210 : :
4211 : 312 : if (!same_type_check (i, 0, j, 1))
4212 : : return false;
4213 : :
4214 : 312 : if (mask->ts.type == BT_BOZ && !gfc_boz2int(mask, i->ts.kind))
4215 : : return false;
4216 : :
4217 : 312 : if (!type_check (mask, 2, BT_INTEGER))
4218 : : return false;
4219 : :
4220 : 312 : if (!same_type_check (i, 0, mask, 2))
4221 : : return false;
4222 : :
4223 : : return true;
4224 : : }
4225 : :
4226 : :
4227 : : bool
4228 : 253 : gfc_check_move_alloc (gfc_expr *from, gfc_expr *to)
4229 : : {
4230 : 253 : if (!variable_check (from, 0, false))
4231 : : return false;
4232 : 248 : if (!allocatable_check (from, 0))
4233 : : return false;
4234 : 242 : if (gfc_is_coindexed (from))
4235 : : {
4236 : 2 : gfc_error ("The FROM argument to MOVE_ALLOC at %L shall not be "
4237 : : "coindexed", &from->where);
4238 : 2 : return false;
4239 : : }
4240 : :
4241 : 240 : if (!variable_check (to, 1, false))
4242 : : return false;
4243 : 240 : if (!allocatable_check (to, 1))
4244 : : return false;
4245 : 239 : if (gfc_is_coindexed (to))
4246 : : {
4247 : 2 : gfc_error ("The TO argument to MOVE_ALLOC at %L shall not be "
4248 : : "coindexed", &to->where);
4249 : 2 : return false;
4250 : : }
4251 : :
4252 : 237 : if (from->ts.type == BT_CLASS && to->ts.type == BT_DERIVED)
4253 : : {
4254 : 1 : gfc_error ("The TO arguments in MOVE_ALLOC at %L must be "
4255 : : "polymorphic if FROM is polymorphic",
4256 : : &to->where);
4257 : 1 : return false;
4258 : : }
4259 : :
4260 : 236 : if (!same_type_check (to, 1, from, 0))
4261 : : return false;
4262 : :
4263 : 236 : if (to->rank != from->rank)
4264 : : {
4265 : 0 : gfc_error ("The FROM and TO arguments of the MOVE_ALLOC intrinsic at %L "
4266 : : "must have the same rank %d/%d", &to->where, from->rank,
4267 : : to->rank);
4268 : 0 : return false;
4269 : : }
4270 : :
4271 : : /* IR F08/0040; cf. 12-006A. */
4272 : 236 : if (gfc_get_corank (to) != gfc_get_corank (from))
4273 : : {
4274 : 4 : gfc_error ("The FROM and TO arguments of the MOVE_ALLOC intrinsic at %L "
4275 : : "must have the same corank %d/%d", &to->where,
4276 : : gfc_get_corank (from), gfc_get_corank (to));
4277 : 4 : return false;
4278 : : }
4279 : :
4280 : : /* This is based losely on F2003 12.4.1.7. It is intended to prevent
4281 : : the likes of to = sym->cmp1->cmp2 and from = sym->cmp1, where cmp1
4282 : : and cmp2 are allocatable. After the allocation is transferred,
4283 : : the 'to' chain is broken by the nullification of the 'from'. A bit
4284 : : of reflection reveals that this can only occur for derived types
4285 : : with recursive allocatable components. */
4286 : 232 : if (to->expr_type == EXPR_VARIABLE && from->expr_type == EXPR_VARIABLE
4287 : 232 : && !strcmp (to->symtree->n.sym->name, from->symtree->n.sym->name))
4288 : : {
4289 : 2 : gfc_ref *to_ref, *from_ref;
4290 : 2 : to_ref = to->ref;
4291 : 2 : from_ref = from->ref;
4292 : 2 : bool aliasing = true;
4293 : :
4294 : 3 : for (; from_ref && to_ref;
4295 : 1 : from_ref = from_ref->next, to_ref = to_ref->next)
4296 : : {
4297 : 2 : if (to_ref->type != from->ref->type)
4298 : : aliasing = false;
4299 : 2 : else if (to_ref->type == REF_ARRAY
4300 : 1 : && to_ref->u.ar.type != AR_FULL
4301 : 1 : && from_ref->u.ar.type != AR_FULL)
4302 : : /* Play safe; assume sections and elements are different. */
4303 : : aliasing = false;
4304 : 1 : else if (to_ref->type == REF_COMPONENT
4305 : 1 : && to_ref->u.c.component != from_ref->u.c.component)
4306 : : aliasing = false;
4307 : :
4308 : 1 : if (!aliasing)
4309 : : break;
4310 : : }
4311 : :
4312 : 2 : if (aliasing)
4313 : : {
4314 : 1 : gfc_error ("The FROM and TO arguments at %L violate aliasing "
4315 : : "restrictions (F2003 12.4.1.7)", &to->where);
4316 : 1 : return false;
4317 : : }
4318 : : }
4319 : :
4320 : : /* CLASS arguments: Make sure the vtab of from is present. */
4321 : 231 : if (to->ts.type == BT_CLASS && !UNLIMITED_POLY (from))
4322 : 88 : gfc_find_vtab (&from->ts);
4323 : :
4324 : : return true;
4325 : : }
4326 : :
4327 : :
4328 : : bool
4329 : 2440 : gfc_check_nearest (gfc_expr *x, gfc_expr *s)
4330 : : {
4331 : 2440 : if (!type_check (x, 0, BT_REAL))
4332 : : return false;
4333 : :
4334 : 2440 : if (!type_check (s, 1, BT_REAL))
4335 : : return false;
4336 : :
4337 : 2440 : if (s->expr_type == EXPR_CONSTANT)
4338 : : {
4339 : 2344 : if (mpfr_sgn (s->value.real) == 0)
4340 : : {
4341 : 4 : gfc_error ("Argument %<S%> of NEAREST at %L shall not be zero",
4342 : : &s->where);
4343 : 4 : return false;
4344 : : }
4345 : : }
4346 : :
4347 : : return true;
4348 : : }
4349 : :
4350 : :
4351 : : bool
4352 : 325 : gfc_check_new_line (gfc_expr *a)
4353 : : {
4354 : 325 : if (!type_check (a, 0, BT_CHARACTER))
4355 : : return false;
4356 : :
4357 : : return true;
4358 : : }
4359 : :
4360 : :
4361 : : bool
4362 : 172 : gfc_check_norm2 (gfc_expr *array, gfc_expr *dim)
4363 : : {
4364 : 172 : if (!type_check (array, 0, BT_REAL))
4365 : : return false;
4366 : :
4367 : 170 : if (!array_check (array, 0))
4368 : : return false;
4369 : :
4370 : 169 : if (!dim_check (dim, 1, false))
4371 : : return false;
4372 : :
4373 : 168 : if (!dim_rank_check (dim, array, false))
4374 : : return false;
4375 : :
4376 : : return true;
4377 : : }
4378 : :
4379 : : bool
4380 : 1411 : gfc_check_null (gfc_expr *mold)
4381 : : {
4382 : 1411 : symbol_attribute attr;
4383 : :
4384 : 1411 : if (mold == NULL)
4385 : : return true;
4386 : :
4387 : 282 : if (mold->expr_type == EXPR_NULL)
4388 : : return true;
4389 : :
4390 : 279 : if (!variable_check (mold, 0, true))
4391 : : return false;
4392 : :
4393 : 279 : attr = gfc_variable_attr (mold, NULL);
4394 : :
4395 : 279 : if (!attr.pointer && !attr.proc_pointer && !attr.allocatable)
4396 : : {
4397 : 0 : gfc_error ("%qs argument of %qs intrinsic at %L must be a POINTER, "
4398 : : "ALLOCATABLE or procedure pointer",
4399 : 0 : gfc_current_intrinsic_arg[0]->name,
4400 : : gfc_current_intrinsic, &mold->where);
4401 : 0 : return false;
4402 : : }
4403 : :
4404 : 279 : if (attr.allocatable
4405 : 279 : && !gfc_notify_std (GFC_STD_F2003, "NULL intrinsic with "
4406 : : "allocatable MOLD at %L", &mold->where))
4407 : : return false;
4408 : :
4409 : : /* F2008, C1242. */
4410 : 278 : if (gfc_is_coindexed (mold))
4411 : : {
4412 : 1 : gfc_error ("%qs argument of %qs intrinsic at %L shall not be "
4413 : 1 : "coindexed", gfc_current_intrinsic_arg[0]->name,
4414 : : gfc_current_intrinsic, &mold->where);
4415 : 1 : return false;
4416 : : }
4417 : :
4418 : : return true;
4419 : : }
4420 : :
4421 : :
4422 : : bool
4423 : 634 : gfc_check_pack (gfc_expr *array, gfc_expr *mask, gfc_expr *vector)
4424 : : {
4425 : 634 : if (!array_check (array, 0))
4426 : : return false;
4427 : :
4428 : 634 : if (!type_check (mask, 1, BT_LOGICAL))
4429 : : return false;
4430 : :
4431 : 634 : if (!gfc_check_conformance (array, mask,
4432 : 634 : _("arguments '%s' and '%s' for intrinsic '%s'"),
4433 : 634 : gfc_current_intrinsic_arg[0]->name,
4434 : 634 : gfc_current_intrinsic_arg[1]->name,
4435 : : gfc_current_intrinsic))
4436 : : return false;
4437 : :
4438 : 633 : if (vector != NULL)
4439 : : {
4440 : 213 : mpz_t array_size, vector_size;
4441 : 213 : bool have_array_size, have_vector_size;
4442 : :
4443 : 213 : if (!same_type_check (array, 0, vector, 2))
4444 : 2 : return false;
4445 : :
4446 : 213 : if (!rank_check (vector, 2, 1))
4447 : : return false;
4448 : :
4449 : : /* VECTOR requires at least as many elements as MASK
4450 : : has .TRUE. values. */
4451 : 213 : have_array_size = gfc_array_size(array, &array_size);
4452 : 213 : have_vector_size = gfc_array_size(vector, &vector_size);
4453 : :
4454 : 213 : if (have_vector_size
4455 : 177 : && (mask->expr_type == EXPR_ARRAY
4456 : 174 : || (mask->expr_type == EXPR_CONSTANT
4457 : 42 : && have_array_size)))
4458 : : {
4459 : 33 : int mask_true_values = 0;
4460 : :
4461 : 33 : if (mask->expr_type == EXPR_ARRAY)
4462 : : {
4463 : 3 : gfc_constructor *mask_ctor;
4464 : 3 : mask_ctor = gfc_constructor_first (mask->value.constructor);
4465 : 42 : while (mask_ctor)
4466 : : {
4467 : 36 : if (mask_ctor->expr->expr_type != EXPR_CONSTANT)
4468 : : {
4469 : : mask_true_values = 0;
4470 : : break;
4471 : : }
4472 : :
4473 : 36 : if (mask_ctor->expr->value.logical)
4474 : 6 : mask_true_values++;
4475 : :
4476 : 36 : mask_ctor = gfc_constructor_next (mask_ctor);
4477 : : }
4478 : : }
4479 : 30 : else if (mask->expr_type == EXPR_CONSTANT && mask->value.logical)
4480 : 12 : mask_true_values = mpz_get_si (array_size);
4481 : :
4482 : 33 : if (mpz_get_si (vector_size) < mask_true_values)
4483 : : {
4484 : 2 : gfc_error ("%qs argument of %qs intrinsic at %L must "
4485 : : "provide at least as many elements as there "
4486 : : "are .TRUE. values in %qs (%ld/%d)",
4487 : 2 : gfc_current_intrinsic_arg[2]->name,
4488 : : gfc_current_intrinsic, &vector->where,
4489 : 2 : gfc_current_intrinsic_arg[1]->name,
4490 : : mpz_get_si (vector_size), mask_true_values);
4491 : 2 : return false;
4492 : : }
4493 : : }
4494 : :
4495 : 199 : if (have_array_size)
4496 : 151 : mpz_clear (array_size);
4497 : 211 : if (have_vector_size)
4498 : 175 : mpz_clear (vector_size);
4499 : : }
4500 : :
4501 : : return true;
4502 : : }
4503 : :
4504 : :
4505 : : bool
4506 : 103 : gfc_check_parity (gfc_expr *mask, gfc_expr *dim)
4507 : : {
4508 : 103 : if (!type_check (mask, 0, BT_LOGICAL))
4509 : : return false;
4510 : :
4511 : 101 : if (!array_check (mask, 0))
4512 : : return false;
4513 : :
4514 : 100 : if (!dim_check (dim, 1, false))
4515 : : return false;
4516 : :
4517 : 99 : if (!dim_rank_check (dim, mask, false))
4518 : : return false;
4519 : :
4520 : : return true;
4521 : : }
4522 : :
4523 : :
4524 : : bool
4525 : 460 : gfc_check_precision (gfc_expr *x)
4526 : : {
4527 : 460 : if (!real_or_complex_check (x, 0))
4528 : : return false;
4529 : :
4530 : : return true;
4531 : : }
4532 : :
4533 : :
4534 : : bool
4535 : 4732 : gfc_check_present (gfc_expr *a)
4536 : : {
4537 : 4732 : gfc_symbol *sym;
4538 : :
4539 : 4732 : if (!variable_check (a, 0, true))
4540 : : return false;
4541 : :
4542 : 4732 : sym = a->symtree->n.sym;
4543 : 4732 : if (!sym->attr.dummy)
4544 : : {
4545 : 0 : gfc_error ("%qs argument of %qs intrinsic at %L must be of a "
4546 : 0 : "dummy variable", gfc_current_intrinsic_arg[0]->name,
4547 : : gfc_current_intrinsic, &a->where);
4548 : 0 : return false;
4549 : : }
4550 : :
4551 : : /* For CLASS, the optional attribute might be set at either location. */
4552 : 4732 : if ((sym->ts.type != BT_CLASS || !CLASS_DATA (sym)->attr.optional)
4553 : 4732 : && !sym->attr.optional)
4554 : : {
4555 : 0 : gfc_error ("%qs argument of %qs intrinsic at %L must be of "
4556 : : "an OPTIONAL dummy variable",
4557 : 0 : gfc_current_intrinsic_arg[0]->name, gfc_current_intrinsic,
4558 : : &a->where);
4559 : 0 : return false;
4560 : : }
4561 : :
4562 : : /* 13.14.82 PRESENT(A)
4563 : : ......
4564 : : Argument. A shall be the name of an optional dummy argument that is
4565 : : accessible in the subprogram in which the PRESENT function reference
4566 : : appears... */
4567 : :
4568 : 4732 : if (a->ref != NULL
4569 : 2295 : && !(a->ref->next == NULL && a->ref->type == REF_ARRAY
4570 : 2294 : && (a->ref->u.ar.type == AR_FULL
4571 : 21 : || (a->ref->u.ar.type == AR_ELEMENT
4572 : 21 : && a->ref->u.ar.as->rank == 0))))
4573 : : {
4574 : 2 : gfc_error ("%qs argument of %qs intrinsic at %L must not be a "
4575 : 2 : "subobject of %qs", gfc_current_intrinsic_arg[0]->name,
4576 : : gfc_current_intrinsic, &a->where, sym->name);
4577 : 2 : return false;
4578 : : }
4579 : :
4580 : : return true;
4581 : : }
4582 : :
4583 : :
4584 : : bool
4585 : 49 : gfc_check_radix (gfc_expr *x)
4586 : : {
4587 : 49 : if (!int_or_real_check (x, 0))
4588 : : return false;
4589 : :
4590 : : return true;
4591 : : }
4592 : :
4593 : :
4594 : : bool
4595 : 136 : gfc_check_range (gfc_expr *x)
4596 : : {
4597 : 136 : if (!numeric_check (x, 0))
4598 : : return false;
4599 : :
4600 : : return true;
4601 : : }
4602 : :
4603 : :
4604 : : bool
4605 : 1318 : gfc_check_rank (gfc_expr *a)
4606 : : {
4607 : : /* Any data object is allowed; a "data object" is a "constant (4.1.3),
4608 : : variable (6), or subobject of a constant (2.4.3.2.3)" (F2008, 1.3.45). */
4609 : :
4610 : 1318 : bool is_variable = true;
4611 : :
4612 : : /* Functions returning pointers are regarded as variable, cf. F2008, R602. */
4613 : 1318 : if (a->expr_type == EXPR_FUNCTION)
4614 : 0 : is_variable = a->value.function.esym
4615 : 0 : ? a->value.function.esym->result->attr.pointer
4616 : 0 : : a->symtree->n.sym->result->attr.pointer;
4617 : :
4618 : 1318 : if (a->expr_type == EXPR_OP
4619 : 1318 : || a->expr_type == EXPR_NULL
4620 : 1318 : || a->expr_type == EXPR_COMPCALL
4621 : 1318 : || a->expr_type == EXPR_PPC
4622 : 1318 : || a->ts.type == BT_PROCEDURE
4623 : 1318 : || !is_variable)
4624 : : {
4625 : 0 : gfc_error ("The argument of the RANK intrinsic at %L must be a data "
4626 : : "object", &a->where);
4627 : 0 : return false;
4628 : : }
4629 : :
4630 : : return true;
4631 : : }
4632 : :
4633 : :
4634 : : bool
4635 : 3216 : gfc_check_real (gfc_expr *a, gfc_expr *kind)
4636 : : {
4637 : 3216 : if (!kind_check (kind, 1, BT_REAL))
4638 : : return false;
4639 : :
4640 : : /* BOZ is dealt with in gfc_simplify_real. */
4641 : 3216 : if (a->ts.type == BT_BOZ)
4642 : : return true;
4643 : :
4644 : 3131 : if (!numeric_check (a, 0))
4645 : : return false;
4646 : :
4647 : : return true;
4648 : : }
4649 : :
4650 : :
4651 : : bool
4652 : 7 : gfc_check_rename (gfc_expr *path1, gfc_expr *path2)
4653 : : {
4654 : 7 : if (!type_check (path1, 0, BT_CHARACTER))
4655 : : return false;
4656 : 7 : if (!kind_value_check (path1, 0, gfc_default_character_kind))
4657 : : return false;
4658 : :
4659 : 5 : if (!type_check (path2, 1, BT_CHARACTER))
4660 : : return false;
4661 : 5 : if (!kind_value_check (path2, 1, gfc_default_character_kind))
4662 : : return false;
4663 : :
4664 : : return true;
4665 : : }
4666 : :
4667 : :
4668 : : bool
4669 : 15 : gfc_check_rename_sub (gfc_expr *path1, gfc_expr *path2, gfc_expr *status)
4670 : : {
4671 : 15 : if (!type_check (path1, 0, BT_CHARACTER))
4672 : : return false;
4673 : 15 : if (!kind_value_check (path1, 0, gfc_default_character_kind))
4674 : : return false;
4675 : :
4676 : 11 : if (!type_check (path2, 1, BT_CHARACTER))
4677 : : return false;
4678 : 11 : if (!kind_value_check (path2, 1, gfc_default_character_kind))
4679 : : return false;
4680 : :
4681 : 9 : if (status == NULL)
4682 : : return true;
4683 : :
4684 : 7 : if (!type_check (status, 2, BT_INTEGER))
4685 : : return false;
4686 : :
4687 : 7 : if (!scalar_check (status, 2))
4688 : : return false;
4689 : :
4690 : : return true;
4691 : : }
4692 : :
4693 : :
4694 : : bool
4695 : 1433 : gfc_check_repeat (gfc_expr *x, gfc_expr *y)
4696 : : {
4697 : 1433 : if (!type_check (x, 0, BT_CHARACTER))
4698 : : return false;
4699 : :
4700 : 1433 : if (!scalar_check (x, 0))
4701 : : return false;
4702 : :
4703 : 1433 : if (!type_check (y, 0, BT_INTEGER))
4704 : : return false;
4705 : :
4706 : 1433 : if (!scalar_check (y, 1))
4707 : : return false;
4708 : :
4709 : : return true;
4710 : : }
4711 : :
4712 : :
4713 : : bool
4714 : 5136 : gfc_check_reshape (gfc_expr *source, gfc_expr *shape,
4715 : : gfc_expr *pad, gfc_expr *order)
4716 : : {
4717 : 5136 : mpz_t size;
4718 : 5136 : mpz_t nelems;
4719 : 5136 : int shape_size;
4720 : 5136 : bool shape_is_const;
4721 : :
4722 : 5136 : if (!array_check (source, 0))
4723 : : return false;
4724 : :
4725 : 5135 : if (!rank_check (shape, 1, 1))
4726 : : return false;
4727 : :
4728 : 5135 : if (!type_check (shape, 1, BT_INTEGER))
4729 : : return false;
4730 : :
4731 : 5135 : if (!gfc_array_size (shape, &size))
4732 : : {
4733 : 0 : gfc_error ("%<shape%> argument of %<reshape%> intrinsic at %L must be an "
4734 : : "array of constant size", &shape->where);
4735 : 0 : return false;
4736 : : }
4737 : :
4738 : 5135 : shape_size = mpz_get_ui (size);
4739 : 5135 : mpz_clear (size);
4740 : :
4741 : 5135 : if (shape_size <= 0)
4742 : : {
4743 : 1 : gfc_error ("%qs argument of %qs intrinsic at %L is empty",
4744 : 1 : gfc_current_intrinsic_arg[1]->name, gfc_current_intrinsic,
4745 : : &shape->where);
4746 : 1 : return false;
4747 : : }
4748 : 5134 : else if (shape_size > GFC_MAX_DIMENSIONS)
4749 : : {
4750 : 1 : gfc_error ("%<shape%> argument of %<reshape%> intrinsic at %L has more "
4751 : : "than %d elements", &shape->where, GFC_MAX_DIMENSIONS);
4752 : 1 : return false;
4753 : : }
4754 : :
4755 : 5133 : gfc_simplify_expr (shape, 0);
4756 : 5133 : shape_is_const = gfc_is_constant_array_expr (shape);
4757 : :
4758 : 5133 : if (shape->expr_type == EXPR_ARRAY && shape_is_const)
4759 : : {
4760 : : gfc_expr *e;
4761 : : int i, extent;
4762 : 15660 : for (i = 0; i < shape_size; ++i)
4763 : : {
4764 : 10766 : e = gfc_constructor_lookup_expr (shape->value.constructor, i);
4765 : 10766 : if (e == NULL)
4766 : : break;
4767 : 10766 : if (e->expr_type != EXPR_CONSTANT)
4768 : 0 : continue;
4769 : :
4770 : 10766 : gfc_extract_int (e, &extent);
4771 : 10766 : if (extent < 0)
4772 : : {
4773 : 4 : gfc_error ("%qs argument of %qs intrinsic at %L has "
4774 : : "negative element (%d)",
4775 : 4 : gfc_current_intrinsic_arg[1]->name,
4776 : : gfc_current_intrinsic, &shape->where, extent);
4777 : 4 : return false;
4778 : : }
4779 : : }
4780 : : }
4781 : :
4782 : 5129 : if (pad != NULL)
4783 : : {
4784 : 367 : if (!same_type_check (source, 0, pad, 2))
4785 : : return false;
4786 : :
4787 : 367 : if (!array_check (pad, 2))
4788 : : return false;
4789 : : }
4790 : :
4791 : 5129 : if (order != NULL)
4792 : : {
4793 : 136 : if (!array_check (order, 3))
4794 : : return false;
4795 : :
4796 : 136 : if (!type_check (order, 3, BT_INTEGER))
4797 : : return false;
4798 : :
4799 : 135 : if (order->expr_type == EXPR_ARRAY && gfc_is_constant_array_expr (order))
4800 : : {
4801 : : int i, order_size, dim, perm[GFC_MAX_DIMENSIONS];
4802 : : gfc_expr *e;
4803 : :
4804 : 1232 : for (i = 0; i < GFC_MAX_DIMENSIONS; ++i)
4805 : 1155 : perm[i] = 0;
4806 : :
4807 : 77 : gfc_array_size (order, &size);
4808 : 77 : order_size = mpz_get_ui (size);
4809 : 77 : mpz_clear (size);
4810 : :
4811 : 77 : if (order_size != shape_size)
4812 : : {
4813 : 1 : gfc_error ("%qs argument of %qs intrinsic at %L "
4814 : : "has wrong number of elements (%d/%d)",
4815 : 1 : gfc_current_intrinsic_arg[3]->name,
4816 : : gfc_current_intrinsic, &order->where,
4817 : : order_size, shape_size);
4818 : 3 : return false;
4819 : : }
4820 : :
4821 : 232 : for (i = 1; i <= order_size; ++i)
4822 : : {
4823 : 158 : e = gfc_constructor_lookup_expr (order->value.constructor, i-1);
4824 : 158 : if (e->expr_type != EXPR_CONSTANT)
4825 : 0 : continue;
4826 : :
4827 : 158 : gfc_extract_int (e, &dim);
4828 : :
4829 : 158 : if (dim < 1 || dim > order_size)
4830 : : {
4831 : 1 : gfc_error ("%qs argument of %qs intrinsic at %L "
4832 : : "has out-of-range dimension (%d)",
4833 : 1 : gfc_current_intrinsic_arg[3]->name,
4834 : : gfc_current_intrinsic, &e->where, dim);
4835 : 1 : return false;
4836 : : }
4837 : :
4838 : 157 : if (perm[dim-1] != 0)
4839 : : {
4840 : 1 : gfc_error ("%qs argument of %qs intrinsic at %L has "
4841 : : "invalid permutation of dimensions (dimension "
4842 : : "%qd duplicated)",
4843 : 1 : gfc_current_intrinsic_arg[3]->name,
4844 : : gfc_current_intrinsic, &e->where, dim);
4845 : 1 : return false;
4846 : : }
4847 : :
4848 : 156 : perm[dim-1] = 1;
4849 : : }
4850 : : }
4851 : : }
4852 : :
4853 : 5125 : if (pad == NULL && shape->expr_type == EXPR_ARRAY && shape_is_const
4854 : 4574 : && !(source->expr_type == EXPR_VARIABLE && source->symtree->n.sym->as
4855 : 612 : && source->symtree->n.sym->as->type == AS_ASSUMED_SIZE))
4856 : : {
4857 : : /* Check the match in size between source and destination. */
4858 : 4573 : if (gfc_array_size (source, &nelems))
4859 : : {
4860 : 4384 : gfc_constructor *c;
4861 : 4384 : bool test;
4862 : :
4863 : :
4864 : 4384 : mpz_init_set_ui (size, 1);
4865 : 4384 : for (c = gfc_constructor_first (shape->value.constructor);
4866 : 13799 : c; c = gfc_constructor_next (c))
4867 : 9415 : mpz_mul (size, size, c->expr->value.integer);
4868 : :
4869 : 4384 : test = mpz_cmp (nelems, size) < 0 && mpz_cmp_ui (size, 0) > 0;
4870 : 4384 : mpz_clear (nelems);
4871 : 4384 : mpz_clear (size);
4872 : :
4873 : 4384 : if (test)
4874 : : {
4875 : 11 : gfc_error ("Without padding, there are not enough elements "
4876 : : "in the intrinsic RESHAPE source at %L to match "
4877 : : "the shape", &source->where);
4878 : 11 : return false;
4879 : : }
4880 : : }
4881 : : }
4882 : :
4883 : : return true;
4884 : : }
4885 : :
4886 : :
4887 : : bool
4888 : 752 : gfc_check_same_type_as (gfc_expr *a, gfc_expr *b)
4889 : : {
4890 : 752 : if (a->ts.type != BT_DERIVED && a->ts.type != BT_CLASS)
4891 : : {
4892 : 4 : gfc_error ("%qs argument of %qs intrinsic at %L "
4893 : : "cannot be of type %s",
4894 : 4 : gfc_current_intrinsic_arg[0]->name,
4895 : : gfc_current_intrinsic,
4896 : : &a->where, gfc_typename (a));
4897 : 4 : return false;
4898 : : }
4899 : :
4900 : 748 : if (!(gfc_type_is_extensible (a->ts.u.derived) || UNLIMITED_POLY (a)))
4901 : : {
4902 : 0 : gfc_error ("%qs argument of %qs intrinsic at %L "
4903 : : "must be of an extensible type",
4904 : 0 : gfc_current_intrinsic_arg[0]->name, gfc_current_intrinsic,
4905 : : &a->where);
4906 : 0 : return false;
4907 : : }
4908 : :
4909 : 748 : if (b->ts.type != BT_DERIVED && b->ts.type != BT_CLASS)
4910 : : {
4911 : 0 : gfc_error ("%qs argument of %qs intrinsic at %L "
4912 : : "cannot be of type %s",
4913 : 0 : gfc_current_intrinsic_arg[0]->name,
4914 : : gfc_current_intrinsic,
4915 : : &b->where, gfc_typename (b));
4916 : 0 : return false;
4917 : : }
4918 : :
4919 : 748 : if (!(gfc_type_is_extensible (b->ts.u.derived) || UNLIMITED_POLY (b)))
4920 : : {
4921 : 2 : gfc_error ("%qs argument of %qs intrinsic at %L "
4922 : : "must be of an extensible type",
4923 : 2 : gfc_current_intrinsic_arg[1]->name, gfc_current_intrinsic,
4924 : : &b->where);
4925 : 2 : return false;
4926 : : }
4927 : :
4928 : : return true;
4929 : : }
4930 : :
4931 : :
4932 : : bool
4933 : 84 : gfc_check_scale (gfc_expr *x, gfc_expr *i)
4934 : : {
4935 : 84 : if (!type_check (x, 0, BT_REAL))
4936 : : return false;
4937 : :
4938 : 84 : if (!type_check (i, 1, BT_INTEGER))
4939 : : return false;
4940 : :
4941 : : return true;
4942 : : }
4943 : :
4944 : :
4945 : : bool
4946 : 418 : gfc_check_scan (gfc_expr *x, gfc_expr *y, gfc_expr *z, gfc_expr *kind)
4947 : : {
4948 : 418 : if (!type_check (x, 0, BT_CHARACTER))
4949 : : return false;
4950 : :
4951 : 418 : if (!type_check (y, 1, BT_CHARACTER))
4952 : : return false;
4953 : :
4954 : 418 : if (z != NULL && !type_check (z, 2, BT_LOGICAL))
4955 : : return false;
4956 : :
4957 : 418 : if (!kind_check (kind, 3, BT_INTEGER))
4958 : : return false;
4959 : 418 : if (kind && !gfc_notify_std (GFC_STD_F2003, "%qs intrinsic "
4960 : : "with KIND argument at %L",
4961 : : gfc_current_intrinsic, &kind->where))
4962 : : return false;
4963 : :
4964 : 418 : if (!same_type_check (x, 0, y, 1))
4965 : : return false;
4966 : :
4967 : : return true;
4968 : : }
4969 : :
4970 : :
4971 : : bool
4972 : 52 : gfc_check_secnds (gfc_expr *r)
4973 : : {
4974 : 52 : if (!type_check (r, 0, BT_REAL))
4975 : : return false;
4976 : :
4977 : 52 : if (!kind_value_check (r, 0, 4))
4978 : : return false;
4979 : :
4980 : 52 : if (!scalar_check (r, 0))
4981 : : return false;
4982 : :
4983 : : return true;
4984 : : }
4985 : :
4986 : :
4987 : : bool
4988 : 214 : gfc_check_selected_char_kind (gfc_expr *name)
4989 : : {
4990 : 214 : if (!type_check (name, 0, BT_CHARACTER))
4991 : : return false;
4992 : :
4993 : 213 : if (!kind_value_check (name, 0, gfc_default_character_kind))
4994 : : return false;
4995 : :
4996 : 211 : if (!scalar_check (name, 0))
4997 : : return false;
4998 : :
4999 : : return true;
5000 : : }
5001 : :
5002 : :
5003 : : bool
5004 : 239 : gfc_check_selected_int_kind (gfc_expr *r)
5005 : : {
5006 : 239 : if (!type_check (r, 0, BT_INTEGER))
5007 : : return false;
5008 : :
5009 : 239 : if (!scalar_check (r, 0))
5010 : : return false;
5011 : :
5012 : : return true;
5013 : : }
5014 : :
5015 : :
5016 : : bool
5017 : 730 : gfc_check_selected_real_kind (gfc_expr *p, gfc_expr *r, gfc_expr *radix)
5018 : : {
5019 : 730 : if (p == NULL && r == NULL
5020 : 730 : && !gfc_notify_std (GFC_STD_F2008, "SELECTED_REAL_KIND with"
5021 : : " neither %<P%> nor %<R%> argument at %L",
5022 : : gfc_current_intrinsic_where))
5023 : : return false;
5024 : :
5025 : 729 : if (p)
5026 : : {
5027 : 687 : if (!type_check (p, 0, BT_INTEGER))
5028 : : return false;
5029 : :
5030 : 687 : if (!scalar_check (p, 0))
5031 : : return false;
5032 : : }
5033 : :
5034 : 728 : if (r)
5035 : : {
5036 : 246 : if (!type_check (r, 1, BT_INTEGER))
5037 : : return false;
5038 : :
5039 : 246 : if (!scalar_check (r, 1))
5040 : : return false;
5041 : : }
5042 : :
5043 : 727 : if (radix)
5044 : : {
5045 : 53 : if (!type_check (radix, 1, BT_INTEGER))
5046 : : return false;
5047 : :
5048 : 53 : if (!scalar_check (radix, 1))
5049 : : return false;
5050 : :
5051 : 53 : if (!gfc_notify_std (GFC_STD_F2008, "%qs intrinsic with "
5052 : : "RADIX argument at %L", gfc_current_intrinsic,
5053 : : &radix->where))
5054 : : return false;
5055 : : }
5056 : :
5057 : : return true;
5058 : : }
5059 : :
5060 : :
5061 : : bool
5062 : 412 : gfc_check_set_exponent (gfc_expr *x, gfc_expr *i)
5063 : : {
5064 : 412 : if (!type_check (x, 0, BT_REAL))
5065 : : return false;
5066 : :
5067 : 412 : if (!type_check (i, 1, BT_INTEGER))
5068 : : return false;
5069 : :
5070 : : return true;
5071 : : }
5072 : :
5073 : :
5074 : : bool
5075 : 3359 : gfc_check_shape (gfc_expr *source, gfc_expr *kind)
5076 : : {
5077 : 3359 : gfc_array_ref *ar;
5078 : :
5079 : 3359 : if (gfc_invalid_null_arg (source))
5080 : : return false;
5081 : :
5082 : 3358 : if (!kind_check (kind, 1, BT_INTEGER))
5083 : : return false;
5084 : 3357 : if (kind && !gfc_notify_std (GFC_STD_F2003, "%qs intrinsic "
5085 : : "with KIND argument at %L",
5086 : : gfc_current_intrinsic, &kind->where))
5087 : : return false;
5088 : :
5089 : 3357 : if (source->rank == 0 || source->expr_type != EXPR_VARIABLE)
5090 : : return true;
5091 : :
5092 : 3284 : if (source->ref == NULL)
5093 : : return false;
5094 : :
5095 : 3284 : ar = gfc_find_array_ref (source);
5096 : :
5097 : 3284 : if (ar->as && ar->as->type == AS_ASSUMED_SIZE && ar->type == AR_FULL)
5098 : : {
5099 : 1 : gfc_error ("%<source%> argument of %<shape%> intrinsic at %L must not be "
5100 : : "an assumed size array", &source->where);
5101 : 1 : return false;
5102 : : }
5103 : :
5104 : : return true;
5105 : : }
5106 : :
5107 : :
5108 : : bool
5109 : 6702 : gfc_check_shift (gfc_expr *i, gfc_expr *shift)
5110 : : {
5111 : 6702 : if (!type_check (i, 0, BT_INTEGER))
5112 : : return false;
5113 : :
5114 : 6702 : if (!type_check (shift, 0, BT_INTEGER))
5115 : : return false;
5116 : :
5117 : 6702 : if (!nonnegative_check ("SHIFT", shift))
5118 : : return false;
5119 : :
5120 : 6702 : if (!less_than_bitsize1 ("I", i, "SHIFT", shift, true))
5121 : : return false;
5122 : :
5123 : : return true;
5124 : : }
5125 : :
5126 : :
5127 : : bool
5128 : 328 : gfc_check_sign (gfc_expr *a, gfc_expr *b)
5129 : : {
5130 : 328 : if (!int_or_real_check (a, 0))
5131 : : return false;
5132 : :
5133 : 328 : if (!same_type_check (a, 0, b, 1))
5134 : : return false;
5135 : :
5136 : : return true;
5137 : : }
5138 : :
5139 : :
5140 : : bool
5141 : 10597 : gfc_check_size (gfc_expr *array, gfc_expr *dim, gfc_expr *kind)
5142 : : {
5143 : 10597 : if (!array_check (array, 0))
5144 : : return false;
5145 : :
5146 : 10591 : if (!dim_check (dim, 1, true))
5147 : : return false;
5148 : :
5149 : 10590 : if (!dim_rank_check (dim, array, 0))
5150 : : return false;
5151 : :
5152 : 10586 : if (!kind_check (kind, 2, BT_INTEGER))
5153 : : return false;
5154 : 10585 : if (kind && !gfc_notify_std (GFC_STD_F2003, "%qs intrinsic "
5155 : : "with KIND argument at %L",
5156 : : gfc_current_intrinsic, &kind->where))
5157 : : return false;
5158 : :
5159 : :
5160 : : return true;
5161 : : }
5162 : :
5163 : :
5164 : : bool
5165 : 1801 : gfc_check_sizeof (gfc_expr *arg)
5166 : : {
5167 : 1801 : if (gfc_invalid_null_arg (arg))
5168 : : return false;
5169 : :
5170 : 1800 : if (arg->ts.type == BT_PROCEDURE)
5171 : : {
5172 : 5 : gfc_error ("%qs argument of %qs intrinsic at %L shall not be a procedure",
5173 : 5 : gfc_current_intrinsic_arg[0]->name, gfc_current_intrinsic,
5174 : : &arg->where);
5175 : 5 : return false;
5176 : : }
5177 : :
5178 : 1795 : if (illegal_boz_arg (arg))
5179 : : return false;
5180 : :
5181 : : /* TYPE(*) is acceptable if and only if it uses an array descriptor. */
5182 : 1794 : if (arg->ts.type == BT_ASSUMED
5183 : 165 : && (arg->symtree->n.sym->as == NULL
5184 : 164 : || (arg->symtree->n.sym->as->type != AS_ASSUMED_SHAPE
5185 : 164 : && arg->symtree->n.sym->as->type != AS_DEFERRED
5186 : 98 : && arg->symtree->n.sym->as->type != AS_ASSUMED_RANK)))
5187 : : {
5188 : 1 : gfc_error ("%qs argument of %qs intrinsic at %L shall not be TYPE(*)",
5189 : 1 : gfc_current_intrinsic_arg[0]->name, gfc_current_intrinsic,
5190 : : &arg->where);
5191 : 1 : return false;
5192 : : }
5193 : :
5194 : 1793 : if (arg->rank && arg->expr_type == EXPR_VARIABLE
5195 : 1085 : && arg->symtree->n.sym->as != NULL
5196 : 667 : && arg->symtree->n.sym->as->type == AS_ASSUMED_SIZE && arg->ref
5197 : 1 : && arg->ref->type == REF_ARRAY && arg->ref->u.ar.type == AR_FULL)
5198 : : {
5199 : 1 : gfc_error ("%qs argument of %qs intrinsic at %L shall not be an "
5200 : 1 : "assumed-size array", gfc_current_intrinsic_arg[0]->name,
5201 : : gfc_current_intrinsic, &arg->where);
5202 : 1 : return false;
5203 : : }
5204 : :
5205 : : return true;
5206 : : }
5207 : :
5208 : :
5209 : : /* Check whether an expression is interoperable. When returning false,
5210 : : msg is set to a string telling why the expression is not interoperable,
5211 : : otherwise, it is set to NULL. The msg string can be used in diagnostics.
5212 : : If c_loc is true, character with len > 1 are allowed (cf. Fortran
5213 : : 2003corr5); additionally, assumed-shape/assumed-rank/deferred-shape
5214 : : arrays are permitted. And if c_f_ptr is true, deferred-shape arrays
5215 : : are permitted. */
5216 : :
5217 : : static bool
5218 : 4359 : is_c_interoperable (gfc_expr *expr, const char **msg, bool c_loc, bool c_f_ptr)
5219 : : {
5220 : 4359 : *msg = NULL;
5221 : :
5222 : 4359 : if (expr->expr_type == EXPR_NULL && expr->ts.type == BT_UNKNOWN)
5223 : : {
5224 : 1 : *msg = "NULL() is not interoperable";
5225 : 1 : return false;
5226 : : }
5227 : :
5228 : 4358 : if (expr->ts.type == BT_BOZ)
5229 : : {
5230 : 1 : *msg = "BOZ literal constant";
5231 : 1 : return false;
5232 : : }
5233 : :
5234 : 4357 : if (expr->ts.type == BT_CLASS)
5235 : : {
5236 : 0 : *msg = "Expression is polymorphic";
5237 : 0 : return false;
5238 : : }
5239 : :
5240 : 4357 : if (expr->ts.type == BT_DERIVED && !expr->ts.u.derived->attr.is_bind_c
5241 : 35 : && !expr->ts.u.derived->ts.is_iso_c)
5242 : : {
5243 : 35 : *msg = "Expression is a noninteroperable derived type";
5244 : 35 : return false;
5245 : : }
5246 : :
5247 : 4322 : if (expr->ts.type == BT_PROCEDURE)
5248 : : {
5249 : 4 : *msg = "Procedure unexpected as argument";
5250 : 4 : return false;
5251 : : }
5252 : :
5253 : 4318 : if (gfc_notification_std (GFC_STD_GNU) && expr->ts.type == BT_LOGICAL)
5254 : : {
5255 : : int i;
5256 : 24 : for (i = 0; gfc_logical_kinds[i].kind; i++)
5257 : 24 : if (gfc_logical_kinds[i].kind == expr->ts.kind)
5258 : : return true;
5259 : 0 : *msg = "Extension to use a non-C_Bool-kind LOGICAL";
5260 : 0 : return false;
5261 : : }
5262 : :
5263 : 4905 : if (gfc_notification_std (GFC_STD_GNU) && expr->ts.type == BT_CHARACTER
5264 : 4453 : && expr->ts.kind != 1)
5265 : : {
5266 : 48 : *msg = "Extension to use a non-C_CHAR-kind CHARACTER";
5267 : 48 : return false;
5268 : : }
5269 : :
5270 : 4258 : if (expr->ts.type == BT_CHARACTER) {
5271 : 105 : if (expr->ts.deferred)
5272 : : {
5273 : : /* TS 29113 allows deferred-length strings as dummy arguments,
5274 : : but it is not an interoperable type. */
5275 : 1 : *msg = "Expression shall not be a deferred-length string";
5276 : 1 : return false;
5277 : : }
5278 : :
5279 : 104 : if (expr->ts.u.cl && expr->ts.u.cl->length
5280 : 151 : && !gfc_simplify_expr (expr->ts.u.cl->length, 0))
5281 : 0 : gfc_internal_error ("is_c_interoperable(): gfc_simplify_expr failed");
5282 : :
5283 : 104 : if (!c_loc
5284 : 28 : && expr->ts.u.cl
5285 : 132 : && !gfc_length_one_character_type_p (&expr->ts))
5286 : : {
5287 : 0 : *msg = "Type shall have a character length of 1";
5288 : 0 : return false;
5289 : : }
5290 : : }
5291 : :
5292 : : /* Note: The following checks are about interoperatable variables, Fortran
5293 : : 15.3.5/15.3.6. In intrinsics like C_LOC or in procedure interface, more
5294 : : is allowed, e.g. assumed-shape arrays with TS 29113. */
5295 : :
5296 : 4257 : if (gfc_is_coarray (expr))
5297 : : {
5298 : 0 : *msg = "Coarrays are not interoperable";
5299 : 0 : return false;
5300 : : }
5301 : :
5302 : : /* Checks for C_SIZEOF need to take into account edits to 18-007r1, see
5303 : : https://j3-fortran.org/doc/year/22/22-101r1.txt . */
5304 : 4257 : if (!c_loc && !c_f_ptr && expr->rank > 0 && expr->expr_type == EXPR_VARIABLE)
5305 : : {
5306 : 59 : gfc_array_ref *ar = gfc_find_array_ref (expr);
5307 : 59 : if (ar->type == AR_FULL && ar->as->type == AS_ASSUMED_SIZE)
5308 : : {
5309 : 2 : *msg = "Assumed-size arrays are not interoperable";
5310 : 2 : return false;
5311 : : }
5312 : : }
5313 : :
5314 : : return true;
5315 : : }
5316 : :
5317 : :
5318 : : bool
5319 : 327 : gfc_check_c_sizeof (gfc_expr *arg)
5320 : : {
5321 : 327 : const char *msg;
5322 : :
5323 : 327 : if (!is_c_interoperable (arg, &msg, false, false))
5324 : : {
5325 : 9 : gfc_error ("%qs argument of %qs intrinsic at %L must be an "
5326 : : "interoperable data entity: %s",
5327 : 9 : gfc_current_intrinsic_arg[0]->name, gfc_current_intrinsic,
5328 : : &arg->where, msg);
5329 : 9 : return false;
5330 : : }
5331 : :
5332 : 318 : if (arg->ts.type == BT_ASSUMED)
5333 : : {
5334 : 0 : gfc_error ("%qs argument of %qs intrinsic at %L shall not be "
5335 : : "TYPE(*)",
5336 : 0 : gfc_current_intrinsic_arg[0]->name, gfc_current_intrinsic,
5337 : : &arg->where);
5338 : 0 : return false;
5339 : : }
5340 : :
5341 : 318 : if (arg->rank && arg->expr_type == EXPR_VARIABLE
5342 : 59 : && arg->symtree->n.sym->as != NULL
5343 : 57 : && arg->symtree->n.sym->as->type == AS_ASSUMED_SIZE && arg->ref
5344 : 1 : && arg->ref->type == REF_ARRAY && arg->ref->u.ar.type == AR_FULL)
5345 : : {
5346 : 0 : gfc_error ("%qs argument of %qs intrinsic at %L shall not be an "
5347 : 0 : "assumed-size array", gfc_current_intrinsic_arg[0]->name,
5348 : : gfc_current_intrinsic, &arg->where);
5349 : 0 : return false;
5350 : : }
5351 : :
5352 : : return true;
5353 : : }
5354 : :
5355 : :
5356 : : bool
5357 : 2000 : gfc_check_c_associated (gfc_expr *c_ptr_1, gfc_expr *c_ptr_2)
5358 : : {
5359 : 2000 : if (c_ptr_1->ts.type != BT_DERIVED
5360 : 1999 : || c_ptr_1->ts.u.derived->from_intmod != INTMOD_ISO_C_BINDING
5361 : 1999 : || (c_ptr_1->ts.u.derived->intmod_sym_id != ISOCBINDING_PTR
5362 : 158 : && c_ptr_1->ts.u.derived->intmod_sym_id != ISOCBINDING_FUNPTR))
5363 : : {
5364 : 1 : gfc_error ("Argument C_PTR_1 at %L to C_ASSOCIATED shall have the "
5365 : : "type TYPE(C_PTR) or TYPE(C_FUNPTR)", &c_ptr_1->where);
5366 : 1 : return false;
5367 : : }
5368 : :
5369 : 1999 : if (!scalar_check (c_ptr_1, 0))
5370 : : return false;
5371 : :
5372 : 1998 : if (c_ptr_2
5373 : 342 : && (c_ptr_2->ts.type != BT_DERIVED
5374 : 342 : || c_ptr_2->ts.u.derived->from_intmod != INTMOD_ISO_C_BINDING
5375 : 342 : || (c_ptr_1->ts.u.derived->intmod_sym_id
5376 : 342 : != c_ptr_2->ts.u.derived->intmod_sym_id)))
5377 : : {
5378 : 1 : gfc_error ("Argument C_PTR_2 at %L to C_ASSOCIATED shall have the "
5379 : : "same type as C_PTR_1: %s instead of %s", &c_ptr_1->where,
5380 : : gfc_typename (&c_ptr_1->ts),
5381 : : gfc_typename (&c_ptr_2->ts));
5382 : 1 : return false;
5383 : : }
5384 : :
5385 : 341 : if (c_ptr_2 && !scalar_check (c_ptr_2, 1))
5386 : : return false;
5387 : :
5388 : : return true;
5389 : : }
5390 : :
5391 : :
5392 : : bool
5393 : 558 : gfc_check_c_f_pointer (gfc_expr *cptr, gfc_expr *fptr, gfc_expr *shape)
5394 : : {
5395 : 558 : symbol_attribute attr;
5396 : 558 : const char *msg;
5397 : :
5398 : 558 : if (cptr->ts.type != BT_DERIVED
5399 : 558 : || cptr->ts.u.derived->from_intmod != INTMOD_ISO_C_BINDING
5400 : 558 : || cptr->ts.u.derived->intmod_sym_id != ISOCBINDING_PTR)
5401 : : {
5402 : 2 : gfc_error ("Argument CPTR at %L to C_F_POINTER shall have the "
5403 : : "type TYPE(C_PTR)", &cptr->where);
5404 : 2 : return false;
5405 : : }
5406 : :
5407 : 556 : if (!scalar_check (cptr, 0))
5408 : : return false;
5409 : :
5410 : 556 : attr = gfc_expr_attr (fptr);
5411 : :
5412 : 556 : if (!attr.pointer)
5413 : : {
5414 : 1 : gfc_error ("Argument FPTR at %L to C_F_POINTER must be a pointer",
5415 : : &fptr->where);
5416 : 1 : return false;
5417 : : }
5418 : :
5419 : 555 : if (fptr->ts.type == BT_CLASS)
5420 : : {
5421 : 1 : gfc_error ("FPTR argument at %L to C_F_POINTER shall not be polymorphic",
5422 : : &fptr->where);
5423 : 1 : return false;
5424 : : }
5425 : :
5426 : 554 : if (gfc_is_coindexed (fptr))
5427 : : {
5428 : 0 : gfc_error ("Argument FPTR at %L to C_F_POINTER shall not be "
5429 : : "coindexed", &fptr->where);
5430 : 0 : return false;
5431 : : }
5432 : :
5433 : 554 : if (fptr->rank == 0 && shape)
5434 : : {
5435 : 1 : gfc_error ("Unexpected SHAPE argument at %L to C_F_POINTER with scalar "
5436 : : "FPTR", &fptr->where);
5437 : 1 : return false;
5438 : : }
5439 : 553 : else if (fptr->rank && !shape)
5440 : : {
5441 : 1 : gfc_error ("Expected SHAPE argument to C_F_POINTER with array "
5442 : : "FPTR at %L", &fptr->where);
5443 : 1 : return false;
5444 : : }
5445 : :
5446 : 552 : if (shape && !rank_check (shape, 2, 1))
5447 : : return false;
5448 : :
5449 : 551 : if (shape && !type_check (shape, 2, BT_INTEGER))
5450 : : return false;
5451 : :
5452 : 550 : if (shape)
5453 : : {
5454 : 457 : mpz_t size;
5455 : 457 : if (gfc_array_size (shape, &size))
5456 : : {
5457 : 456 : if (mpz_cmp_ui (size, fptr->rank) != 0)
5458 : : {
5459 : 0 : mpz_clear (size);
5460 : 0 : gfc_error ("SHAPE argument at %L to C_F_POINTER must have the same "
5461 : : "size as the RANK of FPTR", &shape->where);
5462 : 0 : return false;
5463 : : }
5464 : 456 : mpz_clear (size);
5465 : : }
5466 : : }
5467 : :
5468 : 550 : if (fptr->ts.type == BT_CLASS)
5469 : : {
5470 : 0 : gfc_error ("Polymorphic FPTR at %L to C_F_POINTER", &fptr->where);
5471 : 0 : return false;
5472 : : }
5473 : :
5474 : 550 : if (fptr->ts.type == BT_PROCEDURE && attr.function)
5475 : : {
5476 : 2 : gfc_error ("FPTR argument to C_F_POINTER at %L is a function "
5477 : : "returning a pointer", &fptr->where);
5478 : 2 : return false;
5479 : : }
5480 : :
5481 : 548 : if (fptr->rank > 0 && !is_c_interoperable (fptr, &msg, false, true))
5482 : 13 : return gfc_notify_std (GFC_STD_F2018,
5483 : : "Noninteroperable array FPTR argument to "
5484 : 13 : "C_F_POINTER at %L: %s", &fptr->where, msg);
5485 : :
5486 : : return true;
5487 : : }
5488 : :
5489 : :
5490 : : bool
5491 : 62 : gfc_check_c_f_procpointer (gfc_expr *cptr, gfc_expr *fptr)
5492 : : {
5493 : 62 : symbol_attribute attr;
5494 : :
5495 : 62 : if (cptr->ts.type != BT_DERIVED
5496 : 62 : || cptr->ts.u.derived->from_intmod != INTMOD_ISO_C_BINDING
5497 : 62 : || cptr->ts.u.derived->intmod_sym_id != ISOCBINDING_FUNPTR)
5498 : : {
5499 : 3 : gfc_error ("Argument CPTR at %L to C_F_PROCPOINTER shall have the "
5500 : : "type TYPE(C_FUNPTR)", &cptr->where);
5501 : 3 : return false;
5502 : : }
5503 : :
5504 : 59 : if (!scalar_check (cptr, 0))
5505 : : return false;
5506 : :
5507 : 59 : attr = gfc_expr_attr (fptr);
5508 : :
5509 : 59 : if (!attr.proc_pointer)
5510 : : {
5511 : 0 : gfc_error ("Argument FPTR at %L to C_F_PROCPOINTER shall be a procedure "
5512 : : "pointer", &fptr->where);
5513 : 0 : return false;
5514 : : }
5515 : :
5516 : 59 : if (gfc_is_coindexed (fptr))
5517 : : {
5518 : 0 : gfc_error ("Argument FPTR at %L to C_F_PROCPOINTER shall not be "
5519 : : "coindexed", &fptr->where);
5520 : 0 : return false;
5521 : : }
5522 : :
5523 : 59 : if (!attr.is_bind_c)
5524 : 47 : return gfc_notify_std (GFC_STD_F2018, "Noninteroperable procedure "
5525 : 47 : "pointer at %L to C_F_PROCPOINTER", &fptr->where);
5526 : :
5527 : : return true;
5528 : : }
5529 : :
5530 : :
5531 : : bool
5532 : 240 : gfc_check_c_funloc (gfc_expr *x)
5533 : : {
5534 : 240 : symbol_attribute attr;
5535 : :
5536 : 240 : if (gfc_is_coindexed (x))
5537 : : {
5538 : 0 : gfc_error ("Argument X at %L to C_FUNLOC shall not be "
5539 : : "coindexed", &x->where);
5540 : 0 : return false;
5541 : : }
5542 : :
5543 : 240 : attr = gfc_expr_attr (x);
5544 : :
5545 : 240 : if (attr.function && !attr.proc_pointer && x->expr_type == EXPR_VARIABLE
5546 : 123 : && x->symtree->n.sym == x->symtree->n.sym->result)
5547 : 56 : for (gfc_namespace *ns = gfc_current_ns; ns; ns = ns->parent)
5548 : 34 : if (x->symtree->n.sym == ns->proc_name)
5549 : : {
5550 : 3 : gfc_error ("Function result %qs at %L is invalid as X argument "
5551 : : "to C_FUNLOC", x->symtree->n.sym->name, &x->where);
5552 : 3 : return false;
5553 : : }
5554 : :
5555 : 237 : if (attr.flavor != FL_PROCEDURE)
5556 : : {
5557 : 1 : gfc_error ("Argument X at %L to C_FUNLOC shall be a procedure "
5558 : : "or a procedure pointer", &x->where);
5559 : 1 : return false;
5560 : : }
5561 : :
5562 : 236 : if (!attr.is_bind_c)
5563 : 96 : return gfc_notify_std (GFC_STD_F2018, "Noninteroperable procedure "
5564 : 96 : "at %L to C_FUNLOC", &x->where);
5565 : : return true;
5566 : : }
5567 : :
5568 : :
5569 : : bool
5570 : 3581 : gfc_check_c_loc (gfc_expr *x)
5571 : : {
5572 : 3581 : symbol_attribute attr;
5573 : 3581 : const char *msg;
5574 : :
5575 : 3581 : if (gfc_is_coindexed (x))
5576 : : {
5577 : 1 : gfc_error ("Argument X at %L to C_LOC shall not be coindexed", &x->where);
5578 : 1 : return false;
5579 : : }
5580 : :
5581 : 3580 : if (x->ts.type == BT_CLASS)
5582 : : {
5583 : 1 : gfc_error ("X argument at %L to C_LOC shall not be polymorphic",
5584 : : &x->where);
5585 : 1 : return false;
5586 : : }
5587 : :
5588 : 3579 : attr = gfc_expr_attr (x);
5589 : :
5590 : 3579 : if (!attr.pointer
5591 : 2231 : && (x->expr_type != EXPR_VARIABLE || !attr.target
5592 : 2228 : || attr.flavor == FL_PARAMETER))
5593 : : {
5594 : 3 : gfc_error ("Argument X at %L to C_LOC shall have either "
5595 : : "the POINTER or the TARGET attribute", &x->where);
5596 : 3 : return false;
5597 : : }
5598 : :
5599 : 3576 : if (x->ts.type == BT_CHARACTER
5600 : 3576 : && gfc_var_strlen (x) == 0)
5601 : : {
5602 : 0 : gfc_error ("Argument X at %L to C_LOC shall be not be a zero-sized "
5603 : : "string", &x->where);
5604 : 0 : return false;
5605 : : }
5606 : :
5607 : 3576 : if (!is_c_interoperable (x, &msg, true, false))
5608 : : {
5609 : 70 : if (x->ts.type == BT_CLASS)
5610 : : {
5611 : 0 : gfc_error ("Argument at %L to C_LOC shall not be polymorphic",
5612 : : &x->where);
5613 : 0 : return false;
5614 : : }
5615 : :
5616 : 70 : if (x->rank
5617 : 70 : && !gfc_notify_std (GFC_STD_F2018,
5618 : : "Noninteroperable array at %L as"
5619 : : " argument to C_LOC: %s", &x->where, msg))
5620 : : return false;
5621 : : }
5622 : 3506 : else if (x->rank > 0 && gfc_notification_std (GFC_STD_F2008))
5623 : : {
5624 : 7 : gfc_array_ref *ar = gfc_find_array_ref (x);
5625 : :
5626 : 6 : if (ar->as->type != AS_EXPLICIT && ar->as->type != AS_ASSUMED_SIZE
5627 : 5 : && !attr.allocatable
5628 : 11 : && !gfc_notify_std (GFC_STD_F2008,
5629 : : "Array of interoperable type at %L "
5630 : : "to C_LOC which is nonallocatable and neither "
5631 : : "assumed size nor explicit size", &x->where))
5632 : : return false;
5633 : 3 : else if (ar->type != AR_FULL
5634 : 3 : && !gfc_notify_std (GFC_STD_F2008, "Array section at %L "
5635 : : "to C_LOC", &x->where))
5636 : : return false;
5637 : : }
5638 : :
5639 : : return true;
5640 : : }
5641 : :
5642 : :
5643 : : bool
5644 : 19 : gfc_check_sleep_sub (gfc_expr *seconds)
5645 : : {
5646 : 19 : if (!type_check (seconds, 0, BT_INTEGER))
5647 : : return false;
5648 : :
5649 : 19 : if (!scalar_check (seconds, 0))
5650 : : return false;
5651 : :
5652 : : return true;
5653 : : }
5654 : :
5655 : : bool
5656 : 3 : gfc_check_sngl (gfc_expr *a)
5657 : : {
5658 : 3 : if (!type_check (a, 0, BT_REAL))
5659 : : return false;
5660 : :
5661 : 3 : if ((a->ts.kind != gfc_default_double_kind)
5662 : 3 : && !gfc_notify_std (GFC_STD_GNU, "non double precision "
5663 : : "REAL argument to %s intrinsic at %L",
5664 : : gfc_current_intrinsic, &a->where))
5665 : : return false;
5666 : :
5667 : : return true;
5668 : : }
5669 : :
5670 : : bool
5671 : 670 : gfc_check_spread (gfc_expr *source, gfc_expr *dim, gfc_expr *ncopies)
5672 : : {
5673 : 670 : if (gfc_invalid_null_arg (source))
5674 : : return false;
5675 : :
5676 : 669 : if (source->rank >= GFC_MAX_DIMENSIONS)
5677 : : {
5678 : 0 : gfc_error ("%qs argument of %qs intrinsic at %L must be less "
5679 : 0 : "than rank %d", gfc_current_intrinsic_arg[0]->name,
5680 : : gfc_current_intrinsic, &source->where, GFC_MAX_DIMENSIONS);
5681 : :
5682 : 0 : return false;
5683 : : }
5684 : :
5685 : 669 : if (dim == NULL)
5686 : : return false;
5687 : :
5688 : 669 : if (!dim_check (dim, 1, false))
5689 : : return false;
5690 : :
5691 : : /* dim_rank_check() does not apply here. */
5692 : 669 : if (dim
5693 : 669 : && dim->expr_type == EXPR_CONSTANT
5694 : 669 : && (mpz_cmp_ui (dim->value.integer, 1) < 0
5695 : 668 : || mpz_cmp_ui (dim->value.integer, source->rank + 1) > 0))
5696 : : {
5697 : 2 : gfc_error ("%qs argument of %qs intrinsic at %L is not a valid "
5698 : 2 : "dimension index", gfc_current_intrinsic_arg[1]->name,
5699 : : gfc_current_intrinsic, &dim->where);
5700 : 2 : return false;
5701 : : }
5702 : :
5703 : 667 : if (!type_check (ncopies, 2, BT_INTEGER))
5704 : : return false;
5705 : :
5706 : 667 : if (!scalar_check (ncopies, 2))
5707 : : return false;
5708 : :
5709 : : return true;
5710 : : }
5711 : :
5712 : :
5713 : : /* Functions for checking FGETC, FPUTC, FGET and FPUT (subroutines and
5714 : : functions). */
5715 : :
5716 : : bool
5717 : 157 : arg_strlen_is_zero (gfc_expr *c, int n)
5718 : : {
5719 : 157 : if (gfc_var_strlen (c) == 0)
5720 : : {
5721 : 2 : gfc_error ("%qs argument of %qs intrinsic at %L must have "
5722 : 2 : "length at least 1", gfc_current_intrinsic_arg[n]->name,
5723 : : gfc_current_intrinsic, &c->where);
5724 : 2 : return true;
5725 : : }
5726 : : return false;
5727 : : }
5728 : :
5729 : : bool
5730 : 155 : gfc_check_fgetputc_sub (gfc_expr *unit, gfc_expr *c, gfc_expr *status)
5731 : : {
5732 : 155 : if (!type_check (unit, 0, BT_INTEGER))
5733 : : return false;
5734 : :
5735 : 155 : if (!scalar_check (unit, 0))
5736 : : return false;
5737 : :
5738 : 155 : if (!type_check (c, 1, BT_CHARACTER))
5739 : : return false;
5740 : 155 : if (!kind_value_check (c, 1, gfc_default_character_kind))
5741 : : return false;
5742 : 149 : if (strcmp (gfc_current_intrinsic, "fgetc") == 0
5743 : 149 : && !variable_check (c, 1, false))
5744 : : return false;
5745 : 148 : if (arg_strlen_is_zero (c, 1))
5746 : : return false;
5747 : :
5748 : 147 : if (status == NULL)
5749 : : return true;
5750 : :
5751 : 58 : if (!type_check (status, 2, BT_INTEGER)
5752 : 58 : || !kind_value_check (status, 2, gfc_default_integer_kind)
5753 : 58 : || !scalar_check (status, 2)
5754 : 116 : || !variable_check (status, 2, false))
5755 : 2 : return false;
5756 : :
5757 : : return true;
5758 : : }
5759 : :
5760 : :
5761 : : bool
5762 : 71 : gfc_check_fgetputc (gfc_expr *unit, gfc_expr *c)
5763 : : {
5764 : 71 : return gfc_check_fgetputc_sub (unit, c, NULL);
5765 : : }
5766 : :
5767 : :
5768 : : bool
5769 : 17 : gfc_check_fgetput_sub (gfc_expr *c, gfc_expr *status)
5770 : : {
5771 : 17 : if (!type_check (c, 0, BT_CHARACTER))
5772 : : return false;
5773 : 17 : if (!kind_value_check (c, 0, gfc_default_character_kind))
5774 : : return false;
5775 : 11 : if (strcmp (gfc_current_intrinsic, "fget") == 0
5776 : 11 : && !variable_check (c, 0, false))
5777 : : return false;
5778 : 9 : if (arg_strlen_is_zero (c, 0))
5779 : : return false;
5780 : :
5781 : 8 : if (status == NULL)
5782 : : return true;
5783 : :
5784 : 2 : if (!type_check (status, 1, BT_INTEGER)
5785 : 2 : || !kind_value_check (status, 1, gfc_default_integer_kind)
5786 : 2 : || !scalar_check (status, 1)
5787 : 4 : || !variable_check (status, 1, false))
5788 : 0 : return false;
5789 : :
5790 : : return true;
5791 : : }
5792 : :
5793 : :
5794 : : bool
5795 : 8 : gfc_check_fgetput (gfc_expr *c)
5796 : : {
5797 : 8 : return gfc_check_fgetput_sub (c, NULL);
5798 : : }
5799 : :
5800 : :
5801 : : bool
5802 : 60 : gfc_check_fseek_sub (gfc_expr *unit, gfc_expr *offset, gfc_expr *whence, gfc_expr *status)
5803 : : {
5804 : 60 : if (!type_check (unit, 0, BT_INTEGER))
5805 : : return false;
5806 : :
5807 : 60 : if (!scalar_check (unit, 0))
5808 : : return false;
5809 : :
5810 : 60 : if (!type_check (offset, 1, BT_INTEGER))
5811 : : return false;
5812 : :
5813 : 60 : if (!scalar_check (offset, 1))
5814 : : return false;
5815 : :
5816 : 60 : if (!type_check (whence, 2, BT_INTEGER))
5817 : : return false;
5818 : :
5819 : 60 : if (!scalar_check (whence, 2))
5820 : : return false;
5821 : :
5822 : 60 : if (status == NULL)
5823 : : return true;
5824 : :
5825 : 54 : if (!type_check (status, 3, BT_INTEGER))
5826 : : return false;
5827 : :
5828 : 54 : if (!kind_value_check (status, 3, 4))
5829 : : return false;
5830 : :
5831 : 54 : if (!scalar_check (status, 3))
5832 : : return false;
5833 : :
5834 : : return true;
5835 : : }
5836 : :
5837 : :
5838 : :
5839 : : bool
5840 : 6 : gfc_check_fstat (gfc_expr *unit, gfc_expr *array)
5841 : : {
5842 : 6 : if (!type_check (unit, 0, BT_INTEGER))
5843 : : return false;
5844 : :
5845 : 6 : if (!scalar_check (unit, 0))
5846 : : return false;
5847 : :
5848 : 6 : if (!type_check (array, 1, BT_INTEGER)
5849 : 6 : || !kind_value_check (unit, 0, gfc_default_integer_kind))
5850 : 0 : return false;
5851 : :
5852 : 6 : if (!array_check (array, 1))
5853 : : return false;
5854 : :
5855 : : return true;
5856 : : }
5857 : :
5858 : :
5859 : : bool
5860 : 6 : gfc_check_fstat_sub (gfc_expr *unit, gfc_expr *array, gfc_expr *status)
5861 : : {
5862 : 6 : if (!type_check (unit, 0, BT_INTEGER))
5863 : : return false;
5864 : :
5865 : 6 : if (!scalar_check (unit, 0))
5866 : : return false;
5867 : :
5868 : 6 : if (!type_check (array, 1, BT_INTEGER)
5869 : 6 : || !kind_value_check (array, 1, gfc_default_integer_kind))
5870 : 0 : return false;
5871 : :
5872 : 6 : if (!array_check (array, 1))
5873 : : return false;
5874 : :
5875 : 6 : if (status == NULL)
5876 : : return true;
5877 : :
5878 : 6 : if (!type_check (status, 2, BT_INTEGER)
5879 : 6 : || !kind_value_check (status, 2, gfc_default_integer_kind))
5880 : 0 : return false;
5881 : :
5882 : 6 : if (!scalar_check (status, 2))
5883 : : return false;
5884 : :
5885 : : return true;
5886 : : }
5887 : :
5888 : :
5889 : : bool
5890 : 102 : gfc_check_ftell (gfc_expr *unit)
5891 : : {
5892 : 102 : if (!type_check (unit, 0, BT_INTEGER))
5893 : : return false;
5894 : :
5895 : 102 : if (!scalar_check (unit, 0))
5896 : : return false;
5897 : :
5898 : : return true;
5899 : : }
5900 : :
5901 : :
5902 : : bool
5903 : 36 : gfc_check_ftell_sub (gfc_expr *unit, gfc_expr *offset)
5904 : : {
5905 : 36 : if (!type_check (unit, 0, BT_INTEGER))
5906 : : return false;
5907 : :
5908 : 36 : if (!scalar_check (unit, 0))
5909 : : return false;
5910 : :
5911 : 36 : if (!type_check (offset, 1, BT_INTEGER))
5912 : : return false;
5913 : :
5914 : 36 : if (!scalar_check (offset, 1))
5915 : : return false;
5916 : :
5917 : : return true;
5918 : : }
5919 : :
5920 : :
5921 : : bool
5922 : 22 : gfc_check_stat (gfc_expr *name, gfc_expr *array)
5923 : : {
5924 : 22 : if (!type_check (name, 0, BT_CHARACTER))
5925 : : return false;
5926 : 22 : if (!kind_value_check (name, 0, gfc_default_character_kind))
5927 : : return false;
5928 : :
5929 : 20 : if (!type_check (array, 1, BT_INTEGER)
5930 : 20 : || !kind_value_check (array, 1, gfc_default_integer_kind))
5931 : 0 : return false;
5932 : :
5933 : 20 : if (!array_check (array, 1))
5934 : : return false;
5935 : :
5936 : : return true;
5937 : : }
5938 : :
5939 : :
5940 : : bool
5941 : 26 : gfc_check_stat_sub (gfc_expr *name, gfc_expr *array, gfc_expr *status)
5942 : : {
5943 : 26 : if (!type_check (name, 0, BT_CHARACTER))
5944 : : return false;
5945 : 26 : if (!kind_value_check (name, 0, gfc_default_character_kind))
5946 : : return false;
5947 : :
5948 : 22 : if (!type_check (array, 1, BT_INTEGER)
5949 : 22 : || !kind_value_check (array, 1, gfc_default_integer_kind))
5950 : 0 : return false;
5951 : :
5952 : 22 : if (!array_check (array, 1))
5953 : : return false;
5954 : :
5955 : 22 : if (status == NULL)
5956 : : return true;
5957 : :
5958 : 20 : if (!type_check (status, 2, BT_INTEGER)
5959 : 20 : || !kind_value_check (array, 1, gfc_default_integer_kind))
5960 : 0 : return false;
5961 : :
5962 : 20 : if (!scalar_check (status, 2))
5963 : : return false;
5964 : :
5965 : : return true;
5966 : : }
5967 : :
5968 : :
5969 : : bool
5970 : 236 : gfc_check_image_index (gfc_expr *coarray, gfc_expr *sub)
5971 : : {
5972 : 236 : mpz_t nelems;
5973 : :
5974 : 236 : if (flag_coarray == GFC_FCOARRAY_NONE)
5975 : : {
5976 : 0 : gfc_fatal_error ("Coarrays disabled at %C, use %<-fcoarray=%> to enable");
5977 : : return false;
5978 : : }
5979 : :
5980 : 236 : if (!coarray_check (coarray, 0))
5981 : : return false;
5982 : :
5983 : 235 : if (sub->rank != 1)
5984 : : {
5985 : 1 : gfc_error ("%s argument to IMAGE_INDEX must be a rank one array at %L",
5986 : 1 : gfc_current_intrinsic_arg[1]->name, &sub->where);
5987 : 1 : return false;
5988 : : }
5989 : :
5990 : 234 : if (sub->ts.type != BT_INTEGER)
5991 : : {
5992 : 1 : gfc_error ("Type of %s argument of IMAGE_INDEX at %L shall be INTEGER",
5993 : 1 : gfc_current_intrinsic_arg[1]->name, &sub->where);
5994 : 1 : return false;
5995 : : }
5996 : :
5997 : 233 : if (gfc_array_size (sub, &nelems))
5998 : : {
5999 : 233 : int corank = gfc_get_corank (coarray);
6000 : :
6001 : 233 : if (mpz_cmp_ui (nelems, corank) != 0)
6002 : : {
6003 : 3 : gfc_error ("The number of array elements of the SUB argument to "
6004 : : "IMAGE_INDEX at %L shall be %d (corank) not %d",
6005 : 3 : &sub->where, corank, (int) mpz_get_si (nelems));
6006 : 3 : mpz_clear (nelems);
6007 : 3 : return false;
6008 : : }
6009 : 230 : mpz_clear (nelems);
6010 : : }
6011 : :
6012 : : return true;
6013 : : }
6014 : :
6015 : :
6016 : : bool
6017 : 774 : gfc_check_num_images (gfc_expr *distance, gfc_expr *failed)
6018 : : {
6019 : 774 : if (flag_coarray == GFC_FCOARRAY_NONE)
6020 : : {
6021 : 0 : gfc_fatal_error ("Coarrays disabled at %C, use %<-fcoarray=%> to enable");
6022 : : return false;
6023 : : }
6024 : :
6025 : 774 : if (distance)
6026 : : {
6027 : 6 : if (!type_check (distance, 0, BT_INTEGER))
6028 : : return false;
6029 : :
6030 : 6 : if (!nonnegative_check ("DISTANCE", distance))
6031 : : return false;
6032 : :
6033 : 6 : if (!scalar_check (distance, 0))
6034 : : return false;
6035 : :
6036 : 6 : if (!gfc_notify_std (GFC_STD_F2018, "DISTANCE= argument to "
6037 : : "NUM_IMAGES at %L", &distance->where))
6038 : : return false;
6039 : : }
6040 : :
6041 : 774 : if (failed)
6042 : : {
6043 : 5 : if (!type_check (failed, 1, BT_LOGICAL))
6044 : : return false;
6045 : :
6046 : 5 : if (!scalar_check (failed, 1))
6047 : : return false;
6048 : :
6049 : 5 : if (!gfc_notify_std (GFC_STD_F2018, "FAILED= argument to "
6050 : : "NUM_IMAGES at %L", &failed->where))
6051 : : return false;
6052 : : }
6053 : :
6054 : : return true;
6055 : : }
6056 : :
6057 : :
6058 : : bool
6059 : 32 : gfc_check_team_number (gfc_expr *team)
6060 : : {
6061 : 32 : if (flag_coarray == GFC_FCOARRAY_NONE)
6062 : : {
6063 : 0 : gfc_fatal_error ("Coarrays disabled at %C, use %<-fcoarray=%> to enable");
6064 : : return false;
6065 : : }
6066 : :
6067 : 32 : if (team)
6068 : : {
6069 : 0 : if (team->ts.type != BT_DERIVED
6070 : 0 : || team->ts.u.derived->from_intmod != INTMOD_ISO_FORTRAN_ENV
6071 : 0 : || team->ts.u.derived->intmod_sym_id != ISOFORTRAN_TEAM_TYPE)
6072 : : {
6073 : 0 : gfc_error ("TEAM argument at %L to the intrinsic TEAM_NUMBER "
6074 : : "shall be of type TEAM_TYPE", &team->where);
6075 : 0 : return false;
6076 : : }
6077 : : }
6078 : : else
6079 : : return true;
6080 : :
6081 : : return true;
6082 : : }
6083 : :
6084 : :
6085 : : bool
6086 : 1449 : gfc_check_this_image (gfc_expr *coarray, gfc_expr *dim, gfc_expr *distance)
6087 : : {
6088 : 1449 : if (flag_coarray == GFC_FCOARRAY_NONE)
6089 : : {
6090 : 0 : gfc_fatal_error ("Coarrays disabled at %C, use %<-fcoarray=%> to enable");
6091 : : return false;
6092 : : }
6093 : :
6094 : 1449 : if (coarray == NULL && dim == NULL && distance == NULL)
6095 : : return true;
6096 : :
6097 : 415 : if (dim != NULL && coarray == NULL)
6098 : : {
6099 : 1 : gfc_error ("DIM argument without COARRAY argument not allowed for "
6100 : : "THIS_IMAGE intrinsic at %L", &dim->where);
6101 : 1 : return false;
6102 : : }
6103 : :
6104 : 414 : if (distance && (coarray || dim))
6105 : : {
6106 : 0 : gfc_error ("The DISTANCE argument may not be specified together with the "
6107 : : "COARRAY or DIM argument in intrinsic at %L",
6108 : : &distance->where);
6109 : 0 : return false;
6110 : : }
6111 : :
6112 : : /* Assume that we have "this_image (distance)". */
6113 : 412 : if (coarray && !gfc_is_coarray (coarray) && coarray->ts.type == BT_INTEGER)
6114 : : {
6115 : 2 : if (dim)
6116 : : {
6117 : 0 : gfc_error ("Unexpected DIM argument with noncoarray argument at %L",
6118 : : &coarray->where);
6119 : 0 : return false;
6120 : : }
6121 : : distance = coarray;
6122 : : }
6123 : :
6124 : 414 : if (distance)
6125 : : {
6126 : 4 : if (!type_check (distance, 2, BT_INTEGER))
6127 : : return false;
6128 : :
6129 : 4 : if (!nonnegative_check ("DISTANCE", distance))
6130 : : return false;
6131 : :
6132 : 4 : if (!scalar_check (distance, 2))
6133 : : return false;
6134 : :
6135 : 4 : if (!gfc_notify_std (GFC_STD_F2018, "DISTANCE= argument to "
6136 : : "THIS_IMAGE at %L", &distance->where))
6137 : : return false;
6138 : :
6139 : : return true;
6140 : : }
6141 : :
6142 : 410 : if (!coarray_check (coarray, 0))
6143 : : return false;
6144 : :
6145 : 410 : if (dim != NULL)
6146 : : {
6147 : 322 : if (!dim_check (dim, 1, false))
6148 : : return false;
6149 : :
6150 : 322 : if (!dim_corank_check (dim, coarray))
6151 : : return false;
6152 : : }
6153 : :
6154 : : return true;
6155 : : }
6156 : :
6157 : : /* Calculate the sizes for transfer, used by gfc_check_transfer and also
6158 : : by gfc_simplify_transfer. Return false if we cannot do so. */
6159 : :
6160 : : bool
6161 : 1092 : gfc_calculate_transfer_sizes (gfc_expr *source, gfc_expr *mold, gfc_expr *size,
6162 : : size_t *source_size, size_t *result_size,
6163 : : size_t *result_length_p)
6164 : : {
6165 : 1092 : size_t result_elt_size;
6166 : :
6167 : 1092 : if (source->expr_type == EXPR_FUNCTION)
6168 : : return false;
6169 : :
6170 : 1091 : if (size && size->expr_type != EXPR_CONSTANT)
6171 : : return false;
6172 : :
6173 : : /* Calculate the size of the source. */
6174 : 1090 : if (!gfc_target_expr_size (source, source_size))
6175 : : return false;
6176 : :
6177 : : /* Determine the size of the element. */
6178 : 1089 : if (!gfc_element_size (mold, &result_elt_size))
6179 : : return false;
6180 : :
6181 : : /* If the storage size of SOURCE is greater than zero and MOLD is an array,
6182 : : * a scalar with the type and type parameters of MOLD shall not have a
6183 : : * storage size equal to zero.
6184 : : * If MOLD is a scalar and SIZE is absent, the result is a scalar.
6185 : : * If MOLD is an array and SIZE is absent, the result is an array and of
6186 : : * rank one. Its size is as small as possible such that its physical
6187 : : * representation is not shorter than that of SOURCE.
6188 : : * If SIZE is present, the result is an array of rank one and size SIZE.
6189 : : */
6190 : 1070 : if (result_elt_size == 0 && *source_size > 0
6191 : 14 : && (mold->expr_type == EXPR_ARRAY || mold->rank))
6192 : : {
6193 : 8 : gfc_error ("%<MOLD%> argument of %<TRANSFER%> intrinsic at %L is an "
6194 : : "array and shall not have storage size 0 when %<SOURCE%> "
6195 : : "argument has size greater than 0", &mold->where);
6196 : 8 : return false;
6197 : : }
6198 : :
6199 : 1062 : if (result_elt_size == 0 && *source_size == 0 && !size)
6200 : : {
6201 : 41 : *result_size = 0;
6202 : 41 : if (result_length_p)
6203 : 40 : *result_length_p = 0;
6204 : 41 : return true;
6205 : : }
6206 : :
6207 : 1021 : if ((result_elt_size > 0 && (mold->expr_type == EXPR_ARRAY || mold->rank))
6208 : 806 : || size)
6209 : : {
6210 : 215 : int result_length;
6211 : :
6212 : 215 : if (size)
6213 : 197 : result_length = (size_t)mpz_get_ui (size->value.integer);
6214 : : else
6215 : : {
6216 : 152 : result_length = *source_size / result_elt_size;
6217 : 152 : if (result_length * result_elt_size < *source_size)
6218 : 0 : result_length += 1;
6219 : : }
6220 : :
6221 : 329 : *result_size = result_length * result_elt_size;
6222 : 329 : if (result_length_p)
6223 : 321 : *result_length_p = result_length;
6224 : : }
6225 : : else
6226 : 692 : *result_size = result_elt_size;
6227 : :
6228 : : return true;
6229 : : }
6230 : :
6231 : :
6232 : : bool
6233 : 2208 : gfc_check_transfer (gfc_expr *source, gfc_expr *mold, gfc_expr *size)
6234 : : {
6235 : 2208 : size_t source_size;
6236 : 2208 : size_t result_size;
6237 : :
6238 : 2208 : if (gfc_invalid_null_arg (source))
6239 : : return false;
6240 : :
6241 : : /* SOURCE shall be a scalar or array of any type. */
6242 : 2205 : if (source->ts.type == BT_PROCEDURE
6243 : 3 : && source->symtree->n.sym->attr.subroutine == 1)
6244 : : {
6245 : 1 : gfc_error ("%<SOURCE%> argument of %<TRANSFER%> intrinsic at %L "
6246 : : "must not be a %s", &source->where,
6247 : : gfc_basic_typename (source->ts.type));
6248 : 1 : return false;
6249 : : }
6250 : :
6251 : 2204 : if (source->ts.type == BT_BOZ && illegal_boz_arg (source))
6252 : : return false;
6253 : :
6254 : 2203 : if (mold->ts.type == BT_BOZ && illegal_boz_arg (mold))
6255 : : return false;
6256 : :
6257 : 2202 : if (gfc_invalid_null_arg (mold))
6258 : : return false;
6259 : :
6260 : : /* MOLD shall be a scalar or array of any type. */
6261 : 2200 : if (mold->ts.type == BT_PROCEDURE
6262 : 2 : && mold->symtree->n.sym->attr.subroutine == 1)
6263 : : {
6264 : 1 : gfc_error ("%<MOLD%> argument of %<TRANSFER%> intrinsic at %L "
6265 : : "must not be a %s", &mold->where,
6266 : : gfc_basic_typename (mold->ts.type));
6267 : 1 : return false;
6268 : : }
6269 : :
6270 : 2199 : if (mold->ts.type == BT_HOLLERITH)
6271 : : {
6272 : 1 : gfc_error ("%<MOLD%> argument of %<TRANSFER%> intrinsic at %L must not be"
6273 : : " %s", &mold->where, gfc_basic_typename (BT_HOLLERITH));
6274 : 1 : return false;
6275 : : }
6276 : :
6277 : : /* SIZE (optional) shall be an integer scalar. The corresponding actual
6278 : : argument shall not be an optional dummy argument. */
6279 : 2198 : if (size != NULL)
6280 : : {
6281 : 417 : if (!type_check (size, 2, BT_INTEGER))
6282 : : {
6283 : 1 : if (size->ts.type == BT_BOZ)
6284 : 1 : reset_boz (size);
6285 : 1 : return false;
6286 : : }
6287 : :
6288 : 416 : if (!scalar_check (size, 2))
6289 : : return false;
6290 : :
6291 : 416 : if (!nonoptional_check (size, 2))
6292 : : return false;
6293 : : }
6294 : :
6295 : 2197 : if (!warn_surprising)
6296 : : return true;
6297 : :
6298 : : /* If we can't calculate the sizes, we cannot check any more.
6299 : : Return true for that case. */
6300 : :
6301 : 52 : if (!gfc_calculate_transfer_sizes (source, mold, size, &source_size,
6302 : : &result_size, NULL))
6303 : : return true;
6304 : :
6305 : 49 : if (source_size < result_size)
6306 : 6 : gfc_warning (OPT_Wsurprising,
6307 : : "Intrinsic TRANSFER at %L has partly undefined result: "
6308 : : "source size %zd < result size %zd", &source->where,
6309 : : source_size, result_size);
6310 : :
6311 : : return true;
6312 : : }
6313 : :
6314 : :
6315 : : bool
6316 : 1194 : gfc_check_transpose (gfc_expr *matrix)
6317 : : {
6318 : 1194 : if (!rank_check (matrix, 0, 2))
6319 : : return false;
6320 : :
6321 : : return true;
6322 : : }
6323 : :
6324 : :
6325 : : bool
6326 : 6960 : gfc_check_ubound (gfc_expr *array, gfc_expr *dim, gfc_expr *kind)
6327 : : {
6328 : 6960 : if (!array_check (array, 0))
6329 : : return false;
6330 : :
6331 : 6959 : if (!dim_check (dim, 1, false))
6332 : : return false;
6333 : :
6334 : 6959 : if (!dim_rank_check (dim, array, 0))
6335 : : return false;
6336 : :
6337 : 6957 : if (!kind_check (kind, 2, BT_INTEGER))
6338 : : return false;
6339 : 6957 : if (kind && !gfc_notify_std (GFC_STD_F2003, "%qs intrinsic "
6340 : : "with KIND argument at %L",
6341 : : gfc_current_intrinsic, &kind->where))
6342 : : return false;
6343 : :
6344 : : return true;
6345 : : }
6346 : :
6347 : :
6348 : : bool
6349 : 265 : gfc_check_ucobound (gfc_expr *coarray, gfc_expr *dim, gfc_expr *kind)
6350 : : {
6351 : 265 : if (flag_coarray == GFC_FCOARRAY_NONE)
6352 : : {
6353 : 0 : gfc_fatal_error ("Coarrays disabled at %C, use %<-fcoarray=%> to enable");
6354 : : return false;
6355 : : }
6356 : :
6357 : 265 : if (!coarray_check (coarray, 0))
6358 : : return false;
6359 : :
6360 : 261 : if (dim != NULL)
6361 : : {
6362 : 176 : if (!dim_check (dim, 1, false))
6363 : : return false;
6364 : :
6365 : 176 : if (!dim_corank_check (dim, coarray))
6366 : : return false;
6367 : : }
6368 : :
6369 : 261 : if (!kind_check (kind, 2, BT_INTEGER))
6370 : : return false;
6371 : :
6372 : : return true;
6373 : : }
6374 : :
6375 : :
6376 : : bool
6377 : 387 : gfc_check_unpack (gfc_expr *vector, gfc_expr *mask, gfc_expr *field)
6378 : : {
6379 : 387 : mpz_t vector_size;
6380 : :
6381 : 387 : if (!rank_check (vector, 0, 1))
6382 : : return false;
6383 : :
6384 : 387 : if (!array_check (mask, 1))
6385 : : return false;
6386 : :
6387 : 387 : if (!type_check (mask, 1, BT_LOGICAL))
6388 : : return false;
6389 : :
6390 : 387 : if (!same_type_check (vector, 0, field, 2))
6391 : : return false;
6392 : :
6393 : 387 : gfc_simplify_expr (mask, 0);
6394 : :
6395 : 387 : if (mask->expr_type == EXPR_ARRAY
6396 : 387 : && gfc_array_size (vector, &vector_size))
6397 : : {
6398 : 40 : int mask_true_count = 0;
6399 : 40 : gfc_constructor *mask_ctor;
6400 : 40 : mask_ctor = gfc_constructor_first (mask->value.constructor);
6401 : 263 : while (mask_ctor)
6402 : : {
6403 : 183 : if (mask_ctor->expr->expr_type != EXPR_CONSTANT)
6404 : : {
6405 : : mask_true_count = 0;
6406 : : break;
6407 : : }
6408 : :
6409 : 183 : if (mask_ctor->expr->value.logical)
6410 : 78 : mask_true_count++;
6411 : :
6412 : 183 : mask_ctor = gfc_constructor_next (mask_ctor);
6413 : : }
6414 : :
6415 : 40 : if (mpz_get_si (vector_size) < mask_true_count)
6416 : : {
6417 : 1 : gfc_error ("%qs argument of %qs intrinsic at %L must "
6418 : : "provide at least as many elements as there "
6419 : : "are .TRUE. values in %qs (%ld/%d)",
6420 : 1 : gfc_current_intrinsic_arg[0]->name, gfc_current_intrinsic,
6421 : 1 : &vector->where, gfc_current_intrinsic_arg[1]->name,
6422 : : mpz_get_si (vector_size), mask_true_count);
6423 : 1 : return false;
6424 : : }
6425 : :
6426 : 39 : mpz_clear (vector_size);
6427 : : }
6428 : :
6429 : 386 : if (mask->rank != field->rank && field->rank != 0)
6430 : : {
6431 : 0 : gfc_error ("%qs argument of %qs intrinsic at %L must have "
6432 : : "the same rank as %qs or be a scalar",
6433 : 0 : gfc_current_intrinsic_arg[2]->name, gfc_current_intrinsic,
6434 : 0 : &field->where, gfc_current_intrinsic_arg[1]->name);
6435 : 0 : return false;
6436 : : }
6437 : :
6438 : 386 : if (mask->rank == field->rank)
6439 : : {
6440 : : int i;
6441 : 688 : for (i = 0; i < field->rank; i++)
6442 : 434 : if (! identical_dimen_shape (mask, i, field, i))
6443 : : {
6444 : 5 : gfc_error ("%qs and %qs arguments of %qs intrinsic at %L "
6445 : : "must have identical shape.",
6446 : 5 : gfc_current_intrinsic_arg[2]->name,
6447 : 5 : gfc_current_intrinsic_arg[1]->name, gfc_current_intrinsic,
6448 : : &field->where);
6449 : : }
6450 : : }
6451 : :
6452 : : return true;
6453 : : }
6454 : :
6455 : :
6456 : : bool
6457 : 250 : gfc_check_verify (gfc_expr *x, gfc_expr *y, gfc_expr *z, gfc_expr *kind)
6458 : : {
6459 : 250 : if (!type_check (x, 0, BT_CHARACTER))
6460 : : return false;
6461 : :
6462 : 250 : if (!same_type_check (x, 0, y, 1))
6463 : : return false;
6464 : :
6465 : 250 : if (z != NULL && !type_check (z, 2, BT_LOGICAL))
6466 : : return false;
6467 : :
6468 : 250 : if (!kind_check (kind, 3, BT_INTEGER))
6469 : : return false;
6470 : 250 : if (kind && !gfc_notify_std (GFC_STD_F2003, "%qs intrinsic "
6471 : : "with KIND argument at %L",
6472 : : gfc_current_intrinsic, &kind->where))
6473 : : return false;
6474 : :
6475 : : return true;
6476 : : }
6477 : :
6478 : :
6479 : : bool
6480 : 2027 : gfc_check_trim (gfc_expr *x)
6481 : : {
6482 : 2027 : if (!type_check (x, 0, BT_CHARACTER))
6483 : : return false;
6484 : :
6485 : 2027 : if (gfc_invalid_null_arg (x))
6486 : : return false;
6487 : :
6488 : 2026 : if (!scalar_check (x, 0))
6489 : : return false;
6490 : :
6491 : : return true;
6492 : : }
6493 : :
6494 : :
6495 : : bool
6496 : 0 : gfc_check_ttynam (gfc_expr *unit)
6497 : : {
6498 : 0 : if (!scalar_check (unit, 0))
6499 : : return false;
6500 : :
6501 : 0 : if (!type_check (unit, 0, BT_INTEGER))
6502 : : return false;
6503 : :
6504 : : return true;
6505 : : }
6506 : :
6507 : :
6508 : : /************* Check functions for intrinsic subroutines *************/
6509 : :
6510 : : bool
6511 : 21 : gfc_check_cpu_time (gfc_expr *time)
6512 : : {
6513 : 21 : if (!scalar_check (time, 0))
6514 : : return false;
6515 : :
6516 : 21 : if (!type_check (time, 0, BT_REAL))
6517 : : return false;
6518 : :
6519 : 21 : if (!variable_check (time, 0, false))
6520 : : return false;
6521 : :
6522 : : return true;
6523 : : }
6524 : :
6525 : :
6526 : : bool
6527 : 193 : gfc_check_date_and_time (gfc_expr *date, gfc_expr *time,
6528 : : gfc_expr *zone, gfc_expr *values)
6529 : : {
6530 : 193 : if (date != NULL)
6531 : : {
6532 : 81 : if (!type_check (date, 0, BT_CHARACTER))
6533 : : return false;
6534 : 81 : if (!kind_value_check (date, 0, gfc_default_character_kind))
6535 : : return false;
6536 : 79 : if (!scalar_check (date, 0))
6537 : : return false;
6538 : 79 : if (!variable_check (date, 0, false))
6539 : : return false;
6540 : : }
6541 : :
6542 : 191 : if (time != NULL)
6543 : : {
6544 : 89 : if (!type_check (time, 1, BT_CHARACTER))
6545 : : return false;
6546 : 89 : if (!kind_value_check (time, 1, gfc_default_character_kind))
6547 : : return false;
6548 : 88 : if (!scalar_check (time, 1))
6549 : : return false;
6550 : 88 : if (!variable_check (time, 1, false))
6551 : : return false;
6552 : : }
6553 : :
6554 : 190 : if (zone != NULL)
6555 : : {
6556 : 80 : if (!type_check (zone, 2, BT_CHARACTER))
6557 : : return false;
6558 : 80 : if (!kind_value_check (zone, 2, gfc_default_character_kind))
6559 : : return false;
6560 : 79 : if (!scalar_check (zone, 2))
6561 : : return false;
6562 : 79 : if (!variable_check (zone, 2, false))
6563 : : return false;
6564 : : }
6565 : :
6566 : 189 : if (values != NULL)
6567 : : {
6568 : 110 : if (!type_check (values, 3, BT_INTEGER))
6569 : : return false;
6570 : 110 : if (!array_check (values, 3))
6571 : : return false;
6572 : 110 : if (!rank_check (values, 3, 1))
6573 : : return false;
6574 : 110 : if (!variable_check (values, 3, false))
6575 : : return false;
6576 : 110 : if (!array_size_check (values, 3, 8))
6577 : : return false;
6578 : :
6579 : 109 : if (values->ts.kind != gfc_default_integer_kind
6580 : 109 : && !gfc_notify_std (GFC_STD_F2018, "VALUES argument of "
6581 : : "DATE_AND_TIME at %L has non-default kind",
6582 : : &values->where))
6583 : : return false;
6584 : :
6585 : : /* F2018:16.9.59 DATE_AND_TIME
6586 : : "VALUES shall be a rank-one array of type integer
6587 : : with a decimal exponent range of at least four."
6588 : : This is a hard limit also required by the implementation in
6589 : : libgfortran. */
6590 : 109 : if (values->ts.kind < 2)
6591 : : {
6592 : 1 : gfc_error ("VALUES argument of DATE_AND_TIME at %L must have "
6593 : : "a decimal exponent range of at least four",
6594 : : &values->where);
6595 : 1 : return false;
6596 : : }
6597 : : }
6598 : :
6599 : : return true;
6600 : : }
6601 : :
6602 : :
6603 : : bool
6604 : 179 : gfc_check_mvbits (gfc_expr *from, gfc_expr *frompos, gfc_expr *len,
6605 : : gfc_expr *to, gfc_expr *topos)
6606 : : {
6607 : 179 : if (!type_check (from, 0, BT_INTEGER))
6608 : : return false;
6609 : :
6610 : 179 : if (!type_check (frompos, 1, BT_INTEGER))
6611 : : return false;
6612 : :
6613 : 179 : if (!type_check (len, 2, BT_INTEGER))
6614 : : return false;
6615 : :
6616 : 179 : if (!same_type_check (from, 0, to, 3))
6617 : : return false;
6618 : :
6619 : 179 : if (!variable_check (to, 3, false))
6620 : : return false;
6621 : :
6622 : 179 : if (!type_check (topos, 4, BT_INTEGER))
6623 : : return false;
6624 : :
6625 : 179 : if (!nonnegative_check ("frompos", frompos))
6626 : : return false;
6627 : :
6628 : 178 : if (!nonnegative_check ("topos", topos))
6629 : : return false;
6630 : :
6631 : 177 : if (!nonnegative_check ("len", len))
6632 : : return false;
6633 : :
6634 : 176 : if (!less_than_bitsize2 ("from", from, "frompos", frompos, "len", len))
6635 : : return false;
6636 : :
6637 : 175 : if (!less_than_bitsize2 ("to", to, "topos", topos, "len", len))
6638 : : return false;
6639 : :
6640 : : return true;
6641 : : }
6642 : :
6643 : :
6644 : : /* Check the arguments for RANDOM_INIT. */
6645 : :
6646 : : bool
6647 : 94 : gfc_check_random_init (gfc_expr *repeatable, gfc_expr *image_distinct)
6648 : : {
6649 : 94 : if (!type_check (repeatable, 0, BT_LOGICAL))
6650 : : return false;
6651 : :
6652 : 93 : if (!scalar_check (repeatable, 0))
6653 : : return false;
6654 : :
6655 : 92 : if (!type_check (image_distinct, 1, BT_LOGICAL))
6656 : : return false;
6657 : :
6658 : 91 : if (!scalar_check (image_distinct, 1))
6659 : : return false;
6660 : :
6661 : : return true;
6662 : : }
6663 : :
6664 : :
6665 : : bool
6666 : 480 : gfc_check_random_number (gfc_expr *harvest)
6667 : : {
6668 : 480 : if (!type_check (harvest, 0, BT_REAL))
6669 : : return false;
6670 : :
6671 : 480 : if (!variable_check (harvest, 0, false))
6672 : : return false;
6673 : :
6674 : : return true;
6675 : : }
6676 : :
6677 : :
6678 : : bool
6679 : 250 : gfc_check_random_seed (gfc_expr *size, gfc_expr *put, gfc_expr *get)
6680 : : {
6681 : 250 : unsigned int nargs = 0, seed_size;
6682 : 250 : locus *where = NULL;
6683 : 250 : mpz_t put_size, get_size;
6684 : :
6685 : : /* Keep the number of bytes in sync with master_state in
6686 : : libgfortran/intrinsics/random.c. */
6687 : 250 : seed_size = 32 / gfc_default_integer_kind;
6688 : :
6689 : 250 : if (size != NULL)
6690 : : {
6691 : 84 : if (size->expr_type != EXPR_VARIABLE
6692 : 84 : || !size->symtree->n.sym->attr.optional)
6693 : 62 : nargs++;
6694 : :
6695 : 84 : if (!scalar_check (size, 0))
6696 : : return false;
6697 : :
6698 : 84 : if (!type_check (size, 0, BT_INTEGER))
6699 : : return false;
6700 : :
6701 : 84 : if (!variable_check (size, 0, false))
6702 : : return false;
6703 : :
6704 : 83 : if (!kind_value_check (size, 0, gfc_default_integer_kind))
6705 : : return false;
6706 : : }
6707 : :
6708 : 249 : if (put != NULL)
6709 : : {
6710 : 75 : if (put->expr_type != EXPR_VARIABLE
6711 : 75 : || !put->symtree->n.sym->attr.optional)
6712 : : {
6713 : 54 : nargs++;
6714 : 54 : where = &put->where;
6715 : : }
6716 : :
6717 : 75 : if (!array_check (put, 1))
6718 : : return false;
6719 : :
6720 : 75 : if (!rank_check (put, 1, 1))
6721 : : return false;
6722 : :
6723 : 75 : if (!type_check (put, 1, BT_INTEGER))
6724 : : return false;
6725 : :
6726 : 75 : if (!kind_value_check (put, 1, gfc_default_integer_kind))
6727 : : return false;
6728 : :
6729 : 75 : if (gfc_array_size (put, &put_size)
6730 : 80 : && mpz_get_ui (put_size) < seed_size)
6731 : 3 : gfc_error ("Size of %qs argument of %qs intrinsic at %L "
6732 : : "too small (%i/%i)",
6733 : 3 : gfc_current_intrinsic_arg[1]->name, gfc_current_intrinsic,
6734 : 3 : &put->where, (int) mpz_get_ui (put_size), seed_size);
6735 : : }
6736 : :
6737 : 249 : if (get != NULL)
6738 : : {
6739 : 130 : if (get->expr_type != EXPR_VARIABLE
6740 : 130 : || !get->symtree->n.sym->attr.optional)
6741 : : {
6742 : 109 : nargs++;
6743 : 109 : where = &get->where;
6744 : : }
6745 : :
6746 : 130 : if (!array_check (get, 2))
6747 : : return false;
6748 : :
6749 : 130 : if (!rank_check (get, 2, 1))
6750 : : return false;
6751 : :
6752 : 130 : if (!type_check (get, 2, BT_INTEGER))
6753 : : return false;
6754 : :
6755 : 130 : if (!variable_check (get, 2, false))
6756 : : return false;
6757 : :
6758 : 130 : if (!kind_value_check (get, 2, gfc_default_integer_kind))
6759 : : return false;
6760 : :
6761 : 130 : if (gfc_array_size (get, &get_size)
6762 : 135 : && mpz_get_ui (get_size) < seed_size)
6763 : 3 : gfc_error ("Size of %qs argument of %qs intrinsic at %L "
6764 : : "too small (%i/%i)",
6765 : 3 : gfc_current_intrinsic_arg[2]->name, gfc_current_intrinsic,
6766 : 3 : &get->where, (int) mpz_get_ui (get_size), seed_size);
6767 : : }
6768 : :
6769 : : /* RANDOM_SEED may not have more than one non-optional argument. */
6770 : 249 : if (nargs > 1)
6771 : 1 : gfc_error ("Too many arguments to %s at %L", gfc_current_intrinsic, where);
6772 : :
6773 : : return true;
6774 : : }
6775 : :
6776 : : bool
6777 : 401 : gfc_check_fe_runtime_error (gfc_actual_arglist *a)
6778 : : {
6779 : 401 : gfc_expr *e;
6780 : 401 : size_t len, i;
6781 : 401 : int num_percent, nargs;
6782 : :
6783 : 401 : e = a->expr;
6784 : 401 : if (e->expr_type != EXPR_CONSTANT)
6785 : : return true;
6786 : :
6787 : 401 : len = e->value.character.length;
6788 : 401 : if (e->value.character.string[len-1] != '\0')
6789 : 0 : gfc_internal_error ("fe_runtime_error string must be null terminated");
6790 : :
6791 : : num_percent = 0;
6792 : 27901 : for (i=0; i<len-1; i++)
6793 : 27500 : if (e->value.character.string[i] == '%')
6794 : 802 : num_percent ++;
6795 : :
6796 : : nargs = 0;
6797 : 1604 : for (; a; a = a->next)
6798 : 1203 : nargs ++;
6799 : :
6800 : 401 : if (nargs -1 != num_percent)
6801 : 0 : gfc_internal_error ("fe_runtime_error: Wrong number of arguments (%d instead of %d)",
6802 : : nargs, num_percent++);
6803 : :
6804 : : return true;
6805 : : }
6806 : :
6807 : : bool
6808 : 0 : gfc_check_second_sub (gfc_expr *time)
6809 : : {
6810 : 0 : if (!scalar_check (time, 0))
6811 : : return false;
6812 : :
6813 : 0 : if (!type_check (time, 0, BT_REAL))
6814 : : return false;
6815 : :
6816 : 0 : if (!kind_value_check (time, 0, 4))
6817 : : return false;
6818 : :
6819 : : return true;
6820 : : }
6821 : :
6822 : :
6823 : : /* COUNT and COUNT_MAX of SYSTEM_CLOCK are scalar, default-kind integer
6824 : : variables in Fortran 95. In Fortran 2003 and later, they can be of any
6825 : : kind, and COUNT_RATE can be of type real. Note, count, count_rate, and
6826 : : count_max are all optional arguments */
6827 : :
6828 : : bool
6829 : 212 : gfc_check_system_clock (gfc_expr *count, gfc_expr *count_rate,
6830 : : gfc_expr *count_max)
6831 : : {
6832 : 212 : int first_int_kind = -1;
6833 : :
6834 : 212 : if (count != NULL)
6835 : : {
6836 : 207 : if (!scalar_check (count, 0))
6837 : : return false;
6838 : :
6839 : 207 : if (!type_check (count, 0, BT_INTEGER))
6840 : : return false;
6841 : :
6842 : 207 : if (count->ts.kind != gfc_default_integer_kind
6843 : 207 : && !gfc_notify_std (GFC_STD_F2003, "COUNT argument to "
6844 : : "SYSTEM_CLOCK at %L has non-default kind",
6845 : : &count->where))
6846 : : return false;
6847 : :
6848 : 206 : if (count->ts.kind < gfc_default_integer_kind
6849 : 206 : && !gfc_notify_std (GFC_STD_F2023_DEL,
6850 : : "COUNT argument to SYSTEM_CLOCK at %L "
6851 : : "with kind smaller than default integer",
6852 : : &count->where))
6853 : : return false;
6854 : :
6855 : 205 : if (!variable_check (count, 0, false))
6856 : : return false;
6857 : :
6858 : 205 : first_int_kind = count->ts.kind;
6859 : : }
6860 : :
6861 : 210 : if (count_rate != NULL)
6862 : : {
6863 : 194 : if (!scalar_check (count_rate, 1))
6864 : : return false;
6865 : :
6866 : 194 : if (!variable_check (count_rate, 1, false))
6867 : : return false;
6868 : :
6869 : 194 : if (count_rate->ts.type == BT_REAL)
6870 : : {
6871 : 120 : if (!gfc_notify_std (GFC_STD_F2003, "Real COUNT_RATE argument to "
6872 : : "SYSTEM_CLOCK at %L", &count_rate->where))
6873 : : return false;
6874 : : }
6875 : : else
6876 : : {
6877 : 74 : if (!type_check (count_rate, 1, BT_INTEGER))
6878 : : return false;
6879 : :
6880 : 74 : if (count_rate->ts.kind != gfc_default_integer_kind
6881 : 74 : && !gfc_notify_std (GFC_STD_F2003, "COUNT_RATE argument to "
6882 : : "SYSTEM_CLOCK at %L has non-default kind",
6883 : : &count_rate->where))
6884 : : return false;
6885 : :
6886 : 73 : if (count_rate->ts.kind < gfc_default_integer_kind
6887 : 73 : && !gfc_notify_std (GFC_STD_F2023_DEL,
6888 : : "COUNT_RATE argument to SYSTEM_CLOCK at %L "
6889 : : "with kind smaller than default integer",
6890 : : &count_rate->where))
6891 : : return false;
6892 : :
6893 : 72 : if (first_int_kind < 0)
6894 : 2 : first_int_kind = count_rate->ts.kind;
6895 : : }
6896 : :
6897 : : }
6898 : :
6899 : 206 : if (count_max != NULL)
6900 : : {
6901 : 189 : if (!scalar_check (count_max, 2))
6902 : : return false;
6903 : :
6904 : 189 : if (!type_check (count_max, 2, BT_INTEGER))
6905 : : return false;
6906 : :
6907 : 189 : if (count_max->ts.kind != gfc_default_integer_kind
6908 : 189 : && !gfc_notify_std (GFC_STD_F2003, "COUNT_MAX argument to "
6909 : : "SYSTEM_CLOCK at %L has non-default kind",
6910 : : &count_max->where))
6911 : : return false;
6912 : :
6913 : 188 : if (!variable_check (count_max, 2, false))
6914 : : return false;
6915 : :
6916 : 188 : if (count_max->ts.kind < gfc_default_integer_kind
6917 : 188 : && !gfc_notify_std (GFC_STD_F2023_DEL,
6918 : : "COUNT_MAX argument to SYSTEM_CLOCK at %L "
6919 : : "with kind smaller than default integer",
6920 : : &count_max->where))
6921 : : return false;
6922 : :
6923 : 187 : if (first_int_kind < 0)
6924 : 0 : first_int_kind = count_max->ts.kind;
6925 : : }
6926 : :
6927 : 204 : if (first_int_kind > 0)
6928 : : {
6929 : 203 : if (count_rate
6930 : 188 : && count_rate->ts.type == BT_INTEGER
6931 : 71 : && count_rate->ts.kind != first_int_kind
6932 : 235 : && !gfc_notify_std (GFC_STD_F2023_DEL,
6933 : : "integer arguments to SYSTEM_CLOCK at %L "
6934 : : "with different kind parameters",
6935 : : &count_rate->where))
6936 : : return false;
6937 : :
6938 : 187 : if (count_max && count_max->ts.kind != first_int_kind
6939 : 284 : && !gfc_notify_std (GFC_STD_F2023_DEL,
6940 : : "integer arguments to SYSTEM_CLOCK at %L "
6941 : : "with different kind parameters",
6942 : : &count_max->where))
6943 : : return false;
6944 : : }
6945 : :
6946 : : return true;
6947 : : }
6948 : :
6949 : :
6950 : : bool
6951 : 2 : gfc_check_irand (gfc_expr *x)
6952 : : {
6953 : 2 : if (x == NULL)
6954 : : return true;
6955 : :
6956 : 0 : if (!scalar_check (x, 0))
6957 : : return false;
6958 : :
6959 : 0 : if (!type_check (x, 0, BT_INTEGER))
6960 : : return false;
6961 : :
6962 : 0 : if (!kind_value_check (x, 0, 4))
6963 : : return false;
6964 : :
6965 : : return true;
6966 : : }
6967 : :
6968 : :
6969 : : bool
6970 : 0 : gfc_check_alarm_sub (gfc_expr *seconds, gfc_expr *handler, gfc_expr *status)
6971 : : {
6972 : 0 : if (!scalar_check (seconds, 0))
6973 : : return false;
6974 : 0 : if (!type_check (seconds, 0, BT_INTEGER))
6975 : : return false;
6976 : :
6977 : 0 : if (!int_or_proc_check (handler, 1))
6978 : : return false;
6979 : 0 : if (handler->ts.type == BT_INTEGER && !scalar_check (handler, 1))
6980 : : return false;
6981 : :
6982 : 0 : if (status == NULL)
6983 : : return true;
6984 : :
6985 : 0 : if (!scalar_check (status, 2))
6986 : : return false;
6987 : 0 : if (!type_check (status, 2, BT_INTEGER))
6988 : : return false;
6989 : 0 : if (!kind_value_check (status, 2, gfc_default_integer_kind))
6990 : : return false;
6991 : :
6992 : : return true;
6993 : : }
6994 : :
6995 : :
6996 : : bool
6997 : 8 : gfc_check_rand (gfc_expr *x)
6998 : : {
6999 : 8 : if (x == NULL)
7000 : : return true;
7001 : :
7002 : 1 : if (!scalar_check (x, 0))
7003 : : return false;
7004 : :
7005 : 1 : if (!type_check (x, 0, BT_INTEGER))
7006 : : return false;
7007 : :
7008 : 1 : if (!kind_value_check (x, 0, 4))
7009 : : return false;
7010 : :
7011 : : return true;
7012 : : }
7013 : :
7014 : :
7015 : : bool
7016 : 0 : gfc_check_srand (gfc_expr *x)
7017 : : {
7018 : 0 : if (!scalar_check (x, 0))
7019 : : return false;
7020 : :
7021 : 0 : if (!type_check (x, 0, BT_INTEGER))
7022 : : return false;
7023 : :
7024 : 0 : if (!kind_value_check (x, 0, 4))
7025 : : return false;
7026 : :
7027 : : return true;
7028 : : }
7029 : :
7030 : :
7031 : : bool
7032 : 2 : gfc_check_ctime_sub (gfc_expr *time, gfc_expr *result)
7033 : : {
7034 : 2 : if (!scalar_check (time, 0))
7035 : : return false;
7036 : 2 : if (!type_check (time, 0, BT_INTEGER))
7037 : : return false;
7038 : :
7039 : 2 : if (!type_check (result, 1, BT_CHARACTER))
7040 : : return false;
7041 : 2 : if (!kind_value_check (result, 1, gfc_default_character_kind))
7042 : : return false;
7043 : :
7044 : : return true;
7045 : : }
7046 : :
7047 : :
7048 : : bool
7049 : 1 : gfc_check_dtime_etime (gfc_expr *x)
7050 : : {
7051 : 1 : if (!array_check (x, 0))
7052 : : return false;
7053 : :
7054 : 1 : if (!rank_check (x, 0, 1))
7055 : : return false;
7056 : :
7057 : 1 : if (!variable_check (x, 0, false))
7058 : : return false;
7059 : :
7060 : 1 : if (!type_check (x, 0, BT_REAL))
7061 : : return false;
7062 : :
7063 : 1 : if (!kind_value_check (x, 0, 4))
7064 : : return false;
7065 : :
7066 : : return true;
7067 : : }
7068 : :
7069 : :
7070 : : bool
7071 : 1 : gfc_check_dtime_etime_sub (gfc_expr *values, gfc_expr *time)
7072 : : {
7073 : 1 : if (!array_check (values, 0))
7074 : : return false;
7075 : :
7076 : 1 : if (!rank_check (values, 0, 1))
7077 : : return false;
7078 : :
7079 : 1 : if (!variable_check (values, 0, false))
7080 : : return false;
7081 : :
7082 : 1 : if (!type_check (values, 0, BT_REAL))
7083 : : return false;
7084 : :
7085 : 1 : if (!kind_value_check (values, 0, 4))
7086 : : return false;
7087 : :
7088 : 1 : if (!scalar_check (time, 1))
7089 : : return false;
7090 : :
7091 : 1 : if (!type_check (time, 1, BT_REAL))
7092 : : return false;
7093 : :
7094 : 1 : if (!kind_value_check (time, 1, 4))
7095 : : return false;
7096 : :
7097 : : return true;
7098 : : }
7099 : :
7100 : :
7101 : : bool
7102 : 2 : gfc_check_fdate_sub (gfc_expr *date)
7103 : : {
7104 : 2 : if (!type_check (date, 0, BT_CHARACTER))
7105 : : return false;
7106 : 2 : if (!kind_value_check (date, 0, gfc_default_character_kind))
7107 : : return false;
7108 : :
7109 : : return true;
7110 : : }
7111 : :
7112 : :
7113 : : bool
7114 : 3 : gfc_check_gerror (gfc_expr *msg)
7115 : : {
7116 : 3 : if (!type_check (msg, 0, BT_CHARACTER))
7117 : : return false;
7118 : 3 : if (!kind_value_check (msg, 0, gfc_default_character_kind))
7119 : : return false;
7120 : :
7121 : : return true;
7122 : : }
7123 : :
7124 : :
7125 : : bool
7126 : 10 : gfc_check_getcwd_sub (gfc_expr *cwd, gfc_expr *status)
7127 : : {
7128 : 10 : if (!type_check (cwd, 0, BT_CHARACTER))
7129 : : return false;
7130 : 10 : if (!kind_value_check (cwd, 0, gfc_default_character_kind))
7131 : : return false;
7132 : :
7133 : 8 : if (status == NULL)
7134 : : return true;
7135 : :
7136 : 1 : if (!scalar_check (status, 1))
7137 : : return false;
7138 : :
7139 : 1 : if (!type_check (status, 1, BT_INTEGER))
7140 : : return false;
7141 : :
7142 : : return true;
7143 : : }
7144 : :
7145 : :
7146 : : bool
7147 : 56 : gfc_check_getarg (gfc_expr *pos, gfc_expr *value)
7148 : : {
7149 : 56 : if (!type_check (pos, 0, BT_INTEGER))
7150 : : return false;
7151 : :
7152 : 56 : if (pos->ts.kind > gfc_default_integer_kind)
7153 : : {
7154 : 0 : gfc_error ("%qs argument of %qs intrinsic at %L must be of a kind "
7155 : : "not wider than the default kind (%d)",
7156 : 0 : gfc_current_intrinsic_arg[0]->name, gfc_current_intrinsic,
7157 : : &pos->where, gfc_default_integer_kind);
7158 : 0 : return false;
7159 : : }
7160 : :
7161 : 56 : if (!type_check (value, 1, BT_CHARACTER))
7162 : : return false;
7163 : 56 : if (!kind_value_check (value, 1, gfc_default_character_kind))
7164 : : return false;
7165 : :
7166 : : return true;
7167 : : }
7168 : :
7169 : :
7170 : : bool
7171 : 3 : gfc_check_getlog (gfc_expr *msg)
7172 : : {
7173 : 3 : if (!type_check (msg, 0, BT_CHARACTER))
7174 : : return false;
7175 : 3 : if (!kind_value_check (msg, 0, gfc_default_character_kind))
7176 : : return false;
7177 : :
7178 : : return true;
7179 : : }
7180 : :
7181 : :
7182 : : bool
7183 : 3 : gfc_check_exit (gfc_expr *status)
7184 : : {
7185 : 3 : if (status == NULL)
7186 : : return true;
7187 : :
7188 : 2 : if (!type_check (status, 0, BT_INTEGER))
7189 : : return false;
7190 : :
7191 : 2 : if (!scalar_check (status, 0))
7192 : : return false;
7193 : :
7194 : : return true;
7195 : : }
7196 : :
7197 : :
7198 : : bool
7199 : 25 : gfc_check_flush (gfc_expr *unit)
7200 : : {
7201 : 25 : if (unit == NULL)
7202 : : return true;
7203 : :
7204 : 12 : if (!type_check (unit, 0, BT_INTEGER))
7205 : : return false;
7206 : :
7207 : 12 : if (!scalar_check (unit, 0))
7208 : : return false;
7209 : :
7210 : : return true;
7211 : : }
7212 : :
7213 : :
7214 : : bool
7215 : 10 : gfc_check_free (gfc_expr *i)
7216 : : {
7217 : 10 : if (!type_check (i, 0, BT_INTEGER))
7218 : : return false;
7219 : :
7220 : 10 : if (!scalar_check (i, 0))
7221 : : return false;
7222 : :
7223 : : return true;
7224 : : }
7225 : :
7226 : :
7227 : : bool
7228 : 5 : gfc_check_hostnm (gfc_expr *name)
7229 : : {
7230 : 5 : if (!type_check (name, 0, BT_CHARACTER))
7231 : : return false;
7232 : 5 : if (!kind_value_check (name, 0, gfc_default_character_kind))
7233 : : return false;
7234 : :
7235 : : return true;
7236 : : }
7237 : :
7238 : :
7239 : : bool
7240 : 11 : gfc_check_hostnm_sub (gfc_expr *name, gfc_expr *status)
7241 : : {
7242 : 11 : if (!type_check (name, 0, BT_CHARACTER))
7243 : : return false;
7244 : 11 : if (!kind_value_check (name, 0, gfc_default_character_kind))
7245 : : return false;
7246 : :
7247 : 9 : if (status == NULL)
7248 : : return true;
7249 : :
7250 : 7 : if (!scalar_check (status, 1))
7251 : : return false;
7252 : :
7253 : 7 : if (!type_check (status, 1, BT_INTEGER))
7254 : : return false;
7255 : :
7256 : : return true;
7257 : : }
7258 : :
7259 : :
7260 : : bool
7261 : 24 : gfc_check_itime_idate (gfc_expr *values)
7262 : : {
7263 : 24 : if (!array_check (values, 0))
7264 : : return false;
7265 : :
7266 : 24 : if (!rank_check (values, 0, 1))
7267 : : return false;
7268 : :
7269 : 24 : if (!variable_check (values, 0, false))
7270 : : return false;
7271 : :
7272 : 24 : if (!type_check (values, 0, BT_INTEGER))
7273 : : return false;
7274 : :
7275 : 24 : if (!kind_value_check (values, 0, gfc_default_integer_kind))
7276 : : return false;
7277 : :
7278 : : return true;
7279 : : }
7280 : :
7281 : :
7282 : : bool
7283 : 24 : gfc_check_ltime_gmtime (gfc_expr *time, gfc_expr *values)
7284 : : {
7285 : 24 : if (!type_check (time, 0, BT_INTEGER))
7286 : : return false;
7287 : :
7288 : 24 : if (!kind_value_check (time, 0, gfc_default_integer_kind))
7289 : : return false;
7290 : :
7291 : 24 : if (!scalar_check (time, 0))
7292 : : return false;
7293 : :
7294 : 24 : if (!array_check (values, 1))
7295 : : return false;
7296 : :
7297 : 24 : if (!rank_check (values, 1, 1))
7298 : : return false;
7299 : :
7300 : 24 : if (!variable_check (values, 1, false))
7301 : : return false;
7302 : :
7303 : 24 : if (!type_check (values, 1, BT_INTEGER))
7304 : : return false;
7305 : :
7306 : 24 : if (!kind_value_check (values, 1, gfc_default_integer_kind))
7307 : : return false;
7308 : :
7309 : : return true;
7310 : : }
7311 : :
7312 : :
7313 : : bool
7314 : 2 : gfc_check_ttynam_sub (gfc_expr *unit, gfc_expr *name)
7315 : : {
7316 : 2 : if (!scalar_check (unit, 0))
7317 : : return false;
7318 : :
7319 : 2 : if (!type_check (unit, 0, BT_INTEGER))
7320 : : return false;
7321 : :
7322 : 2 : if (!type_check (name, 1, BT_CHARACTER))
7323 : : return false;
7324 : 2 : if (!kind_value_check (name, 1, gfc_default_character_kind))
7325 : : return false;
7326 : :
7327 : : return true;
7328 : : }
7329 : :
7330 : :
7331 : : bool
7332 : 662 : gfc_check_is_contiguous (gfc_expr *array)
7333 : : {
7334 : 662 : if (array->expr_type == EXPR_NULL)
7335 : : {
7336 : 2 : gfc_error ("Actual argument at %L of %qs intrinsic shall be an "
7337 : : "associated pointer", &array->where, gfc_current_intrinsic);
7338 : 2 : return false;
7339 : : }
7340 : :
7341 : 660 : if (!array_check (array, 0))
7342 : : return false;
7343 : :
7344 : : return true;
7345 : : }
7346 : :
7347 : :
7348 : : bool
7349 : 0 : gfc_check_isatty (gfc_expr *unit)
7350 : : {
7351 : 0 : if (unit == NULL)
7352 : : return false;
7353 : :
7354 : 0 : if (!type_check (unit, 0, BT_INTEGER))
7355 : : return false;
7356 : :
7357 : 0 : if (!scalar_check (unit, 0))
7358 : : return false;
7359 : :
7360 : : return true;
7361 : : }
7362 : :
7363 : :
7364 : : bool
7365 : 626 : gfc_check_isnan (gfc_expr *x)
7366 : : {
7367 : 626 : if (!type_check (x, 0, BT_REAL))
7368 : : return false;
7369 : :
7370 : : return true;
7371 : : }
7372 : :
7373 : :
7374 : : bool
7375 : 3 : gfc_check_perror (gfc_expr *string)
7376 : : {
7377 : 3 : if (!type_check (string, 0, BT_CHARACTER))
7378 : : return false;
7379 : 3 : if (!kind_value_check (string, 0, gfc_default_character_kind))
7380 : : return false;
7381 : :
7382 : : return true;
7383 : : }
7384 : :
7385 : :
7386 : : bool
7387 : 0 : gfc_check_umask (gfc_expr *mask)
7388 : : {
7389 : 0 : if (!type_check (mask, 0, BT_INTEGER))
7390 : : return false;
7391 : :
7392 : 0 : if (!scalar_check (mask, 0))
7393 : : return false;
7394 : :
7395 : : return true;
7396 : : }
7397 : :
7398 : :
7399 : : bool
7400 : 0 : gfc_check_umask_sub (gfc_expr *mask, gfc_expr *old)
7401 : : {
7402 : 0 : if (!type_check (mask, 0, BT_INTEGER))
7403 : : return false;
7404 : :
7405 : 0 : if (!scalar_check (mask, 0))
7406 : : return false;
7407 : :
7408 : 0 : if (old == NULL)
7409 : : return true;
7410 : :
7411 : 0 : if (!scalar_check (old, 1))
7412 : : return false;
7413 : :
7414 : 0 : if (!type_check (old, 1, BT_INTEGER))
7415 : : return false;
7416 : :
7417 : : return true;
7418 : : }
7419 : :
7420 : :
7421 : : bool
7422 : 2 : gfc_check_unlink (gfc_expr *name)
7423 : : {
7424 : 2 : if (!type_check (name, 0, BT_CHARACTER))
7425 : : return false;
7426 : 2 : if (!kind_value_check (name, 0, gfc_default_character_kind))
7427 : : return false;
7428 : :
7429 : : return true;
7430 : : }
7431 : :
7432 : :
7433 : : bool
7434 : 12 : gfc_check_unlink_sub (gfc_expr *name, gfc_expr *status)
7435 : : {
7436 : 12 : if (!type_check (name, 0, BT_CHARACTER))
7437 : : return false;
7438 : 12 : if (!kind_value_check (name, 0, gfc_default_character_kind))
7439 : : return false;
7440 : :
7441 : 10 : if (status == NULL)
7442 : : return true;
7443 : :
7444 : 1 : if (!scalar_check (status, 1))
7445 : : return false;
7446 : :
7447 : 1 : if (!type_check (status, 1, BT_INTEGER))
7448 : : return false;
7449 : :
7450 : : return true;
7451 : : }
7452 : :
7453 : :
7454 : : bool
7455 : 1 : gfc_check_signal (gfc_expr *number, gfc_expr *handler)
7456 : : {
7457 : 1 : if (!scalar_check (number, 0))
7458 : : return false;
7459 : 1 : if (!type_check (number, 0, BT_INTEGER))
7460 : : return false;
7461 : :
7462 : 1 : if (!int_or_proc_check (handler, 1))
7463 : : return false;
7464 : 1 : if (handler->ts.type == BT_INTEGER && !scalar_check (handler, 1))
7465 : : return false;
7466 : :
7467 : : return true;
7468 : : }
7469 : :
7470 : :
7471 : : bool
7472 : 0 : gfc_check_signal_sub (gfc_expr *number, gfc_expr *handler, gfc_expr *status)
7473 : : {
7474 : 0 : if (!scalar_check (number, 0))
7475 : : return false;
7476 : 0 : if (!type_check (number, 0, BT_INTEGER))
7477 : : return false;
7478 : :
7479 : 0 : if (!int_or_proc_check (handler, 1))
7480 : : return false;
7481 : 0 : if (handler->ts.type == BT_INTEGER && !scalar_check (handler, 1))
7482 : : return false;
7483 : :
7484 : 0 : if (status == NULL)
7485 : : return true;
7486 : :
7487 : 0 : if (!type_check (status, 2, BT_INTEGER))
7488 : : return false;
7489 : 0 : if (!scalar_check (status, 2))
7490 : : return false;
7491 : :
7492 : : return true;
7493 : : }
7494 : :
7495 : :
7496 : : bool
7497 : 0 : gfc_check_system_sub (gfc_expr *cmd, gfc_expr *status)
7498 : : {
7499 : 0 : if (!type_check (cmd, 0, BT_CHARACTER))
7500 : : return false;
7501 : 0 : if (!kind_value_check (cmd, 0, gfc_default_character_kind))
7502 : : return false;
7503 : :
7504 : 0 : if (!scalar_check (status, 1))
7505 : : return false;
7506 : :
7507 : 0 : if (!type_check (status, 1, BT_INTEGER))
7508 : : return false;
7509 : :
7510 : 0 : if (!kind_value_check (status, 1, gfc_default_integer_kind))
7511 : : return false;
7512 : :
7513 : : return true;
7514 : : }
7515 : :
7516 : :
7517 : : /* This is used for the GNU intrinsics AND, OR and XOR. */
7518 : : bool
7519 : 164 : gfc_check_and (gfc_expr *i, gfc_expr *j)
7520 : : {
7521 : 164 : if (i->ts.type != BT_INTEGER
7522 : 164 : && i->ts.type != BT_LOGICAL
7523 : 25 : && i->ts.type != BT_BOZ)
7524 : : {
7525 : 3 : gfc_error ("%qs argument of %qs intrinsic at %L must be INTEGER, "
7526 : : "LOGICAL, or a BOZ literal constant",
7527 : 3 : gfc_current_intrinsic_arg[0]->name,
7528 : : gfc_current_intrinsic, &i->where);
7529 : 3 : return false;
7530 : : }
7531 : :
7532 : 161 : if (j->ts.type != BT_INTEGER
7533 : 161 : && j->ts.type != BT_LOGICAL
7534 : 28 : && j->ts.type != BT_BOZ)
7535 : : {
7536 : 3 : gfc_error ("%qs argument of %qs intrinsic at %L must be INTEGER, "
7537 : : "LOGICAL, or a BOZ literal constant",
7538 : 3 : gfc_current_intrinsic_arg[1]->name,
7539 : : gfc_current_intrinsic, &j->where);
7540 : 3 : return false;
7541 : : }
7542 : :
7543 : : /* i and j cannot both be BOZ literal constants. */
7544 : 158 : if (!boz_args_check (i, j))
7545 : : return false;
7546 : :
7547 : : /* If i is BOZ and j is integer, convert i to type of j. */
7548 : 154 : if (i->ts.type == BT_BOZ)
7549 : : {
7550 : 18 : if (j->ts.type != BT_INTEGER)
7551 : : {
7552 : 0 : gfc_error ("%qs argument of %qs intrinsic at %L must be INTEGER",
7553 : 0 : gfc_current_intrinsic_arg[1]->name,
7554 : : gfc_current_intrinsic, &j->where);
7555 : 0 : reset_boz (i);
7556 : 0 : return false;
7557 : : }
7558 : 18 : if (!gfc_boz2int (i, j->ts.kind))
7559 : : return false;
7560 : : }
7561 : :
7562 : : /* If j is BOZ and i is integer, convert j to type of i. */
7563 : 154 : if (j->ts.type == BT_BOZ)
7564 : : {
7565 : 21 : if (i->ts.type != BT_INTEGER)
7566 : : {
7567 : 1 : gfc_error ("%qs argument of %qs intrinsic at %L must be INTEGER",
7568 : 1 : gfc_current_intrinsic_arg[0]->name,
7569 : : gfc_current_intrinsic, &j->where);
7570 : 1 : reset_boz (j);
7571 : 1 : return false;
7572 : : }
7573 : 20 : if (!gfc_boz2int (j, i->ts.kind))
7574 : : return false;
7575 : : }
7576 : :
7577 : 153 : if (!same_type_check (i, 0, j, 1, false))
7578 : : return false;
7579 : :
7580 : 146 : if (!scalar_check (i, 0))
7581 : : return false;
7582 : :
7583 : 146 : if (!scalar_check (j, 1))
7584 : : return false;
7585 : :
7586 : : return true;
7587 : : }
7588 : :
7589 : :
7590 : : bool
7591 : 845 : gfc_check_storage_size (gfc_expr *a, gfc_expr *kind)
7592 : : {
7593 : :
7594 : 845 : if (a->expr_type == EXPR_NULL)
7595 : : {
7596 : 1 : gfc_error ("Intrinsic function NULL at %L cannot be an actual "
7597 : : "argument to STORAGE_SIZE, because it returns a "
7598 : : "disassociated pointer", &a->where);
7599 : 1 : return false;
7600 : : }
7601 : :
7602 : 844 : if (a->ts.type == BT_ASSUMED)
7603 : : {
7604 : 0 : gfc_error ("%qs argument of %qs intrinsic at %L shall not be TYPE(*)",
7605 : 0 : gfc_current_intrinsic_arg[0]->name, gfc_current_intrinsic,
7606 : : &a->where);
7607 : 0 : return false;
7608 : : }
7609 : :
7610 : 844 : if (a->ts.type == BT_PROCEDURE)
7611 : : {
7612 : 1 : gfc_error ("%qs argument of %qs intrinsic at %L shall not be a "
7613 : 1 : "procedure", gfc_current_intrinsic_arg[0]->name,
7614 : : gfc_current_intrinsic, &a->where);
7615 : 1 : return false;
7616 : : }
7617 : :
7618 : 843 : if (a->ts.type == BT_BOZ && illegal_boz_arg (a))
7619 : : return false;
7620 : :
7621 : 842 : if (kind == NULL)
7622 : : return true;
7623 : :
7624 : 303 : if (!type_check (kind, 1, BT_INTEGER))
7625 : : return false;
7626 : :
7627 : 302 : if (!scalar_check (kind, 1))
7628 : : return false;
7629 : :
7630 : 301 : if (kind->expr_type != EXPR_CONSTANT)
7631 : : {
7632 : 1 : gfc_error ("%qs argument of %qs intrinsic at %L must be a constant",
7633 : 1 : gfc_current_intrinsic_arg[1]->name, gfc_current_intrinsic,
7634 : : &kind->where);
7635 : 1 : return false;
7636 : : }
7637 : :
7638 : : return true;
7639 : : }
|