{
unsigned int nargs = 0, kiss_size;
locus *where = NULL;
- mpz_t put_size;
+ mpz_t put_size, get_size;
bool have_gfc_real_16; /* Try and mimic HAVE_GFC_REAL_16 in libgfortran. */
have_gfc_real_16 = gfc_validate_kind (BT_REAL, 16, true) != -1;
- /* Keep these values in sync with kiss_size in libgfortran/random.c. */
- kiss_size = have_gfc_real_16 ? 12 : 8;
-
+ /* Keep the number of bytes in sync with kiss_size in
+ libgfortran/intrinsics/random.c. */
+ kiss_size = (have_gfc_real_16 ? 48 : 32) / gfc_default_integer_kind;
+
if (size != NULL)
{
if (size->expr_type != EXPR_VARIABLE
if (gfc_array_size (put, &put_size) == SUCCESS
&& mpz_get_ui (put_size) < kiss_size)
- gfc_error ("Array PUT of intrinsic %s is too small (%i/%i) at %L",
- gfc_current_intrinsic, (int) mpz_get_ui (put_size),
- kiss_size, where);
+ gfc_error ("Size of '%s' argument of '%s' intrinsic at %L "
+ "too small (%i/%i)",
+ gfc_current_intrinsic_arg[1], gfc_current_intrinsic, where,
+ (int) mpz_get_ui (put_size), kiss_size);
}
if (get != NULL)
if (kind_value_check (get, 2, gfc_default_integer_kind) == FAILURE)
return FAILURE;
+
+ if (gfc_array_size (get, &get_size) == SUCCESS
+ && mpz_get_ui (get_size) < kiss_size)
+ gfc_error ("Size of '%s' argument of '%s' intrinsic at %L "
+ "too small (%i/%i)",
+ gfc_current_intrinsic_arg[2], gfc_current_intrinsic, where,
+ (int) mpz_get_ui (get_size), kiss_size);
}
/* RANDOM_SEED may not have more than one non-optional argument. */
! Possible improvement:
! Provide a separate testcase for systems that support REAL(16),
! to test the minimum size of 12 (instead of 8).
+!
+! Updated to check for arrays of unexpected size,
+! this also works for -fdefault-integer-8.
+!
PROGRAM random_seed_1
IMPLICIT NONE
- INTEGER :: small(7)
- CALL RANDOM_SEED(PUT=small) ! { dg-error "is too small" }
+ INTEGER, PARAMETER :: k = selected_real_kind (precision (0.0_8) + 1)
+ INTEGER, PARAMETER :: nbytes = MERGE(48, 32, k == 16)
+
+ ! '+1' to avoid out-of-bounds warnings
+ INTEGER, PARAMETER :: n = nbytes / KIND(n) + 1
+ INTEGER, DIMENSION(n) :: seed
+
+ ! Get seed, array too small
+ CALL RANDOM_SEED(GET=seed(1:(n-2))) ! { dg-error "too small" }
+
+ ! Get seed, array bigger than necessary
+ CALL RANDOM_SEED(GET=seed(1:n))
+
+ ! Get seed, proper size
+ CALL RANDOM_SEED(GET=seed(1:(n-1)))
+
+ ! Put too few bytes
+ CALL RANDOM_SEED(PUT=seed(1:(n-2))) ! { dg-error "too small" }
+
+ ! Put too many bytes
+ CALL RANDOM_SEED(PUT=seed(1:n))
+
+ ! Put the right amount of bytes
+ CALL RANDOM_SEED(PUT=seed(1:(n-1)))
END PROGRAM random_seed_1