Hello world, here is a slight correction: This patch includes the change to the test case.
Regards Thomas
Index: fortran/simplify.c =================================================================== --- fortran/simplify.c (Revision 222431) +++ fortran/simplify.c (Arbeitskopie) @@ -3445,6 +3445,39 @@ simplify_bound (gfc_expr *array, gfc_expr *dim, gf done: + /* If the array shape is assumed shape or explicit, we can simplify lbound + to 1 if the given lower bound is one because this matches what lbound + should return for an empty array. */ + + if (!upper && as && dim && dim->expr_type == EXPR_CONSTANT + && (as->type == AS_ASSUMED_SHAPE || as->type == AS_EXPLICIT) + && ref->u.ar.type != AR_SECTION) + { + /* Watch out for allocatable or pointer dummy arrays, they can have + lower bounds that are not equal to one. */ + if (!(array->symtree && array->symtree->n.sym + && (array->symtree->n.sym->attr.allocatable + || array->symtree->n.sym->attr.pointer))) + { + unsigned long int ndim; + gfc_expr *lower, *res; + + ndim = mpz_get_si (dim->value.integer) - 1; + lower = as->lower[ndim]; + if (lower->expr_type == EXPR_CONSTANT + && mpz_cmp_si (lower->value.integer, 1) == 0) + { + res = gfc_copy_expr (lower); + if (kind) + { + int nkind = mpz_get_si (kind->value.integer); + res->ts.kind = nkind; + } + return res; + } + } + } + if (as && (as->type == AS_DEFERRED || as->type == AS_ASSUMED_SHAPE || as->type == AS_ASSUMED_RANK)) return NULL; Index: testsuite/gfortran.dg/coarray_lib_this_image_2.f90 =================================================================== --- testsuite/gfortran.dg/coarray_lib_this_image_2.f90 (Revision 222431) +++ testsuite/gfortran.dg/coarray_lib_this_image_2.f90 (Arbeitskopie) @@ -20,7 +20,7 @@ end ! { dg-final { scan-tree-dump-times "mylcobound = 5;" 1 "original" } } ! { dg-final { scan-tree-dump-times "parm...dim\\\[1\\\].lbound = 5;" 1 "original" } } ! { dg-final { scan-tree-dump-times "myucobound =\[^\n\r\]* parm...dim\\\[1\\\].lbound \\+ \[^\n\r\]*_gfortran_caf_num_images \\(0, -1\\).? \\+ -?\[0-9\]+\\);" 1 "original" } } -! { dg-final { scan-tree-dump-times "mylbound = parm...dim\\\[0\\\].stride >= 0 && parm...dim\\\[0\\\].ubound >= parm...dim\\\[0\\\].lbound \\|\\| parm...dim\\\[0\\\].stride < 0 \\?\[^\n\r\]* parm...dim\\\[0\\\].lbound : 1;" 1 "original" } } +! { dg-final { scan-tree-dump-times "mylbound = 1;" 1 "original" } } ! { dg-final { scan-tree-dump-times "mythis_image = _gfortran_caf_this_image \\(0\\);" 1 "original" } } ! { dg-final { scan-tree-dump-times "bar \\(&parm.\[0-9\]+, caf_token.\[0-9\]+, \\(integer\\(kind=\[48\]\\)\\) parm.\[0-9\]+.data - \\(integer\\(kind=\[48\]\\)\\) x\\);" 1 "original" } } ! { dg-final { scan-tree-dump-times "_gfortran_caf_init \\(&argc, &argv\\);" 1 "original" } }