diff options
author | Chung-Lin Tang <cltang@codesourcery.com> | 2021-12-03 17:27:17 +0800 |
---|---|---|
committer | Chung-Lin Tang <cltang@codesourcery.com> | 2021-12-03 17:27:17 +0800 |
commit | 6262e3a22b3d86afc116480bc59a7bb30b0cfd40 (patch) | |
tree | d0720683ed7e0cc6e21395c79bb23c9a4d71fb29 /gcc/fortran | |
parent | 31c200c6e110ced8732332376e69c0958985b926 (diff) | |
download | gcc-6262e3a22b3d86afc116480bc59a7bb30b0cfd40.zip gcc-6262e3a22b3d86afc116480bc59a7bb30b0cfd40.tar.gz gcc-6262e3a22b3d86afc116480bc59a7bb30b0cfd40.tar.bz2 |
fortran: Fix setting of array lower bound for named arrays
This patch fixes a case of setting array low-bounds, found for particular uses
of SOURCE=/MOLD=. This adjusts the relevant part in gfc_trans_allocate() to
set e3_has_nodescriptor only for non-named arrays.
2021-12-03 Tobias Burnus <tobias@codesourcery.com>
gcc/fortran/ChangeLog:
* trans-stmt.c (gfc_trans_allocate): Set e3_has_nodescriptor to true
only for non-named arrays.
gcc/testsuite/ChangeLog:
* gfortran.dg/allocate_with_source_26.f90: Adjust testcase.
* gfortran.dg/allocate_with_mold_4.f90: New testcase.
Diffstat (limited to 'gcc/fortran')
-rw-r--r-- | gcc/fortran/trans-stmt.c | 17 |
1 files changed, 7 insertions, 10 deletions
diff --git a/gcc/fortran/trans-stmt.c b/gcc/fortran/trans-stmt.c index 1fc6d3a..6b27b14 100644 --- a/gcc/fortran/trans-stmt.c +++ b/gcc/fortran/trans-stmt.c @@ -6638,16 +6638,13 @@ gfc_trans_allocate (gfc_code * code) else e3rhs = gfc_copy_expr (code->expr3); - // We need to propagate the bounds of the expr3 for source=/mold=; - // however, for nondescriptor arrays, we use internally a lower bound - // of zero instead of one, which needs to be corrected for the allocate obj - if (e3_is == E3_DESC) - { - symbol_attribute attr = gfc_expr_attr (code->expr3); - if (code->expr3->expr_type == EXPR_ARRAY || - (!attr.allocatable && !attr.pointer)) - e3_has_nodescriptor = true; - } + // We need to propagate the bounds of the expr3 for source=/mold=. + // However, for non-named arrays, the lbound has to be 1 and neither the + // bound used inside the called function even when returning an + // allocatable/pointer nor the zero used internally. + if (e3_is == E3_DESC + && code->expr3->expr_type != EXPR_VARIABLE) + e3_has_nodescriptor = true; } /* Loop over all objects to allocate. */ |