Fortran: OpenMP/OpenACC avoid uninit access in size calc for mapping gcc/fortran/ChangeLog: * trans-openmp.cc (gfc_trans_omp_clauses, gfc_omp_finish_clause): Obtain size for mapping only if allocatable array is allocated. gcc/testsuite/ChangeLog: * gfortran.dg/goacc/array-with-dt-1.f90: Run with -O0 and update dg-warning. * gfortran.dg/goacc/pr93464.f90: Likewise. gcc/fortran/trans-openmp.cc | 6 ++++-- gcc/testsuite/gfortran.dg/goacc/array-with-dt-1.f90 | 12 +++++++++--- gcc/testsuite/gfortran.dg/goacc/pr93464.f90 | 8 ++++---- 3 files changed, 17 insertions(+), 9 deletions(-) diff --git a/gcc/fortran/trans-openmp.cc b/gcc/fortran/trans-openmp.cc index 4d56a771349..fad76a4791f 100644 --- a/gcc/fortran/trans-openmp.cc +++ b/gcc/fortran/trans-openmp.cc @@ -1597,7 +1597,8 @@ gfc_omp_finish_clause (tree c, gimple_seq *pre_p, bool openacc) tree size = create_tmp_var (gfc_array_index_type); tree elemsz = TYPE_SIZE_UNIT (gfc_get_element_type (type)); elemsz = fold_convert (gfc_array_index_type, elemsz); - if (GFC_TYPE_ARRAY_AKIND (type) == GFC_ARRAY_POINTER + if (GFC_TYPE_ARRAY_AKIND (type) == GFC_ARRAY_ALLOCATABLE + || GFC_TYPE_ARRAY_AKIND (type) == GFC_ARRAY_POINTER || GFC_TYPE_ARRAY_AKIND (type) == GFC_ARRAY_POINTER_CONT) { stmtblock_t cond_block; @@ -3208,7 +3209,8 @@ gfc_trans_omp_clauses (stmtblock_t *block, gfc_omp_clauses *clauses, /* We have to check for n->sym->attr.dimension because of scalar coarrays. */ - if (n->sym->attr.pointer && n->sym->attr.dimension) + if ((n->sym->attr.pointer || n->sym->attr.allocatable) + && n->sym->attr.dimension) { stmtblock_t cond_block; tree size diff --git a/gcc/testsuite/gfortran.dg/goacc/array-with-dt-1.f90 b/gcc/testsuite/gfortran.dg/goacc/array-with-dt-1.f90 index 136e42acd59..f6880238c89 100644 --- a/gcc/testsuite/gfortran.dg/goacc/array-with-dt-1.f90 +++ b/gcc/testsuite/gfortran.dg/goacc/array-with-dt-1.f90 @@ -1,4 +1,4 @@ -! { dg-additional-options -Wuninitialized } +! { dg-additional-options "-Wuninitialized -O0" } type t integer, allocatable :: A(:,:) @@ -8,9 +8,15 @@ type(t), allocatable :: b(:) ! { dg-note {'b' declared here} {} { target *-*-* } .-1 } !$acc update host(b) -! { dg-warning {'b\.dim\[0\]\.ubound' is used uninitialized} {} { target *-*-* } .-1 } -! { dg-warning {'b\.dim\[0\]\.lbound' is used uninitialized} {} { target *-*-* } .-2 } +! { dg-warning {'b\.dim\[0\]\.ubound' may be used uninitialized} {} { target *-*-* } .-1 } +! { dg-warning {'b\.dim\[0\]\.lbound' may be used uninitialized} {} { target *-*-* } .-2 } + +allocate(b(1)) +!$acc update host(b) !$acc update host(b(:)) + +!$acc update host(b(1)%A) +allocate(b(1)%A(1,1)) !$acc update host(b(1)%A) !$acc update host(b(1)%A(:,:)) end diff --git a/gcc/testsuite/gfortran.dg/goacc/pr93464.f90 b/gcc/testsuite/gfortran.dg/goacc/pr93464.f90 index c92f1d3d8b2..18531abdf77 100644 --- a/gcc/testsuite/gfortran.dg/goacc/pr93464.f90 +++ b/gcc/testsuite/gfortran.dg/goacc/pr93464.f90 @@ -2,17 +2,17 @@ ! ! Contributed by G. Steinmetz -! { dg-additional-options -Wuninitialized } +! { dg-additional-options "-Wuninitialized -O0" } program p character :: c(2) = 'a' character, allocatable :: z(:) ! { dg-note {'z' declared here} {} { target *-*-* } .-1 } !$acc parallel - ! { dg-warning {'z\.dim\[0\]\.ubound' is used uninitialized} {} { target *-*-* } .-1 } - ! { dg-warning {'z\.dim\[0\]\.lbound' is used uninitialized} {} { target *-*-* } .-2 } + ! { dg-warning {'z\.dim\[0\]\.ubound' may be used uninitialized} {} { target *-*-* } .-1 } + ! { dg-warning {'z\.dim\[0\]\.lbound' may be used uninitialized} {} { target *-*-* } .-2 } !$omp target - z = c + if (allocated(z)) z = c !$acc end parallel !$omp end target print *, z