diff options
| author | Paul Thomas <pault@gcc.gnu.org> | 2025-12-06 07:54:39 +0000 |
|---|---|---|
| committer | Paul Thomas <pault@gcc.gnu.org> | 2025-12-06 07:54:39 +0000 |
| commit | e48b0e8c048d2f101d14475affe4b8222f64dbb6 (patch) | |
| tree | 8a2bf3d98eb818858b0f91db53d06e6fef6d3167 /gcc | |
| parent | 8387f1160d28c21592d29f70282eb38104b27356 (diff) | |
| download | gcc-e48b0e8c048d2f101d14475affe4b8222f64dbb6.zip gcc-e48b0e8c048d2f101d14475affe4b8222f64dbb6.tar.gz gcc-e48b0e8c048d2f101d14475affe4b8222f64dbb6.tar.bz2 | |
Fortran: ALLOCATE with array-valued MOLD expression fails [PR122669]
2025-12-06 Paul Thomas <pault@gcc.gnu.org>
gcc/fortran
PR fortran/122669
* resolve.cc (resolve_allocate_deallocate): Mold expressions
with an array reference and a constant size must be resolved
for each allocate object.
gcc/testsuite
PR fortran/122669
* gfortran.dg/pdt_73.f03: New test.
Diffstat (limited to 'gcc')
| -rw-r--r-- | gcc/fortran/resolve.cc | 4 | ||||
| -rw-r--r-- | gcc/testsuite/gfortran.dg/pdt_73.f03 | 18 |
2 files changed, 21 insertions, 1 deletions
diff --git a/gcc/fortran/resolve.cc b/gcc/fortran/resolve.cc index 8e076c6..db6b52f 100644 --- a/gcc/fortran/resolve.cc +++ b/gcc/fortran/resolve.cc @@ -9799,8 +9799,10 @@ done_errmsg: /* Resolving the expr3 in the loop over all objects to allocate would execute loop invariant code for each loop item. Therefore do it just once here. */ + mpz_t nelem; if (code->expr3 && code->expr3->mold - && code->expr3->ts.type == BT_DERIVED) + && code->expr3->ts.type == BT_DERIVED + && !(code->expr3->ref && gfc_array_size (code->expr3, &nelem))) { /* Default initialization via MOLD (non-polymorphic). */ gfc_expr *rhs = gfc_default_initializer (&code->expr3->ts); diff --git a/gcc/testsuite/gfortran.dg/pdt_73.f03 b/gcc/testsuite/gfortran.dg/pdt_73.f03 new file mode 100644 index 0000000..63a9234 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/pdt_73.f03 @@ -0,0 +1,18 @@ +! { dg-do compile } +! +! Tests the fix for pr122669, which falied with the error below. +! +! Contributed by Damian Rouson <damian@archaeologic.codes> +! + implicit none + type tensor_t + real, allocatable :: values_ + end type + type(tensor_t) :: random_inputs(1) + type(tensor_t), allocatable :: outputs(:) + + random_inputs = [tensor_t(1.0)] + allocate(outputs, mold=random_inputs) ! Error: Array specification or array-valued + ! SOURCE= expression required in ALLOCATE statement at (1) + print *, size(outputs) +end |
