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