diff options
author | Harald Anlauf <anlauf@gmx.de> | 2022-07-05 22:20:05 +0200 |
---|---|---|
committer | Harald Anlauf <anlauf@gmx.de> | 2022-07-12 19:18:19 +0200 |
commit | 6e9d5dfc2911e3acc6039ebfe3837e7ba4be197f (patch) | |
tree | 389eb082131642ae3cf61d359c38b838a379beee /gcc/fortran/simplify.cc | |
parent | cab411a2b4b4f6a6b619d0650fade85288a31f9e (diff) | |
download | gcc-6e9d5dfc2911e3acc6039ebfe3837e7ba4be197f.zip gcc-6e9d5dfc2911e3acc6039ebfe3837e7ba4be197f.tar.gz gcc-6e9d5dfc2911e3acc6039ebfe3837e7ba4be197f.tar.bz2 |
Fortran: error recovery simplifying PACK with invalid arguments [PR106049]
gcc/fortran/ChangeLog:
PR fortran/106049
* simplify.cc (is_constant_array_expr): A non-zero-sized constant
array shall have a non-empty constructor. When the constructor is
empty or missing, treat as non-constant.
gcc/testsuite/ChangeLog:
PR fortran/106049
* gfortran.dg/pack_simplify_1.f90: New test.
Diffstat (limited to 'gcc/fortran/simplify.cc')
-rw-r--r-- | gcc/fortran/simplify.cc | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/gcc/fortran/simplify.cc b/gcc/fortran/simplify.cc index ab59fbc..fb72599 100644 --- a/gcc/fortran/simplify.cc +++ b/gcc/fortran/simplify.cc @@ -233,6 +233,18 @@ is_constant_array_expr (gfc_expr *e) if (e->expr_type != EXPR_ARRAY || !gfc_is_constant_expr (e)) return false; + /* A non-zero-sized constant array shall have a non-empty constructor. */ + if (e->rank > 0 && e->shape != NULL && e->value.constructor == NULL) + { + mpz_init_set_ui (size, 1); + for (int j = 0; j < e->rank; j++) + mpz_mul (size, size, e->shape[j]); + bool not_size0 = (mpz_cmp_si (size, 0) != 0); + mpz_clear (size); + if (not_size0) + return false; + } + for (c = gfc_constructor_first (e->value.constructor); c; c = gfc_constructor_next (c)) if (c->expr->expr_type != EXPR_CONSTANT |