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