diff options
author | Tobias Burnus <tobias@codesourcery.com> | 2022-03-11 08:48:58 +0100 |
---|---|---|
committer | Tobias Burnus <tobias@codesourcery.com> | 2022-03-11 08:48:58 +0100 |
commit | 41bda0036ce81e7ac513f325e7b0f41ccf11cbab (patch) | |
tree | 9add88c8a39abefc167dddc6117aa9d376d2d90b | |
parent | 5e28be89665f340368e399a1f2140c96a7a79ee8 (diff) | |
download | gcc-41bda0036ce81e7ac513f325e7b0f41ccf11cbab.zip gcc-41bda0036ce81e7ac513f325e7b0f41ccf11cbab.tar.gz gcc-41bda0036ce81e7ac513f325e7b0f41ccf11cbab.tar.bz2 |
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: Update/add comments;
remove dg-warning for 'is used uninitialized'.
* gfortran.dg/goacc/pr93464.f90: Likewise.
* gfortran.dg/goacc/array-with-dt-1a.f90: New; copied from
gfortran.dg/goacc/array-with-dt-1.f90 but run with -O0. Update
dg-warning for 'may be used uninitialized'.
* gfortran.dg/goacc/pr93464-2.f90: Likewise; copied from
gfortran.dg/goacc/pr93464.f90.
-rw-r--r-- | gcc/fortran/trans-openmp.cc | 6 | ||||
-rw-r--r-- | gcc/testsuite/gfortran.dg/goacc/array-with-dt-1.f90 | 18 | ||||
-rw-r--r-- | gcc/testsuite/gfortran.dg/goacc/array-with-dt-1a.f90 | 27 | ||||
-rw-r--r-- | gcc/testsuite/gfortran.dg/goacc/pr93464-2.f90 | 26 | ||||
-rw-r--r-- | gcc/testsuite/gfortran.dg/goacc/pr93464.f90 | 12 |
5 files changed, 80 insertions, 9 deletions
diff --git a/gcc/fortran/trans-openmp.cc b/gcc/fortran/trans-openmp.cc index 4d56a771..fad76a4 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 136e42a..fb27f6e 100644 --- a/gcc/testsuite/gfortran.dg/goacc/array-with-dt-1.f90 +++ b/gcc/testsuite/gfortran.dg/goacc/array-with-dt-1.f90 @@ -1,15 +1,27 @@ ! { dg-additional-options -Wuninitialized } +! Purpose of this testcase (from the commit log): +! This patch fixes lowering of derived-type mappings which select elements +! of arrays of derived types, and similar. These would previously lead +! to ICEs. + +! This testcase does not show any uninitialized warnings when compiled with -O +! (as done). For -O0, see testcase file 'array-with-dt-1a.f90'. + type t integer, allocatable :: A(:,:) end type t type(t), allocatable :: b(:) -! { dg-note {'b' declared here} {} { target *-*-* } .-1 } + +! Remark: Semantically, the following line requires that 'b' +! is already present on the device. !$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 } + +! Remark: Semantically, the following lines require that b is allocated +! and present on the device. The last line also requires the same for 'A'. + !$acc update host(b(:)) !$acc update host(b(1)%A) !$acc update host(b(1)%A(:,:)) diff --git a/gcc/testsuite/gfortran.dg/goacc/array-with-dt-1a.f90 b/gcc/testsuite/gfortran.dg/goacc/array-with-dt-1a.f90 new file mode 100644 index 0000000..8beaeb4 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/goacc/array-with-dt-1a.f90 @@ -0,0 +1,27 @@ +! { dg-additional-options "-Wuninitialized -O0" } +! +! With -O0 only, 'may be uninitalized' warnings show up. +! For the original testcase, compiled with '-O', +! see testcase file 'array-with-dt-1a.f90' + +type t + integer, allocatable :: A(:,:) +end type t + +type(t), allocatable :: b(:) +! { dg-note {'b' declared here} {} { target *-*-* } .-1 } + +! Remark: Semantically, the following line requires that 'b' +! is already present on the device. + +!$acc update host(b) +! { dg-warning {'b\.dim\[0\]\.ubound' may be used uninitialized} {} { target *-*-* } .-1 } +! { dg-warning {'b\.dim\[0\]\.lbound' may be used uninitialized} {} { target *-*-* } .-2 } + +! Remark: Semantically, the following lines require that b is allocated +! and present on the device. The last line also requires the same for 'A'. + +!$acc update host(b(:)) +!$acc update host(b(1)%A) +!$acc update host(b(1)%A(:,:)) +end diff --git a/gcc/testsuite/gfortran.dg/goacc/pr93464-2.f90 b/gcc/testsuite/gfortran.dg/goacc/pr93464-2.f90 new file mode 100644 index 0000000..5da6a4e --- /dev/null +++ b/gcc/testsuite/gfortran.dg/goacc/pr93464-2.f90 @@ -0,0 +1,26 @@ +! { dg-additional-options "-Wuninitialized -O0" } +! +! PR fortran/93464 +! +! Contributed by G. Steinmetz +! +! Did before ICE in gfc_omp_check_optional_argument + +! Additionally, check for uninitialized warnings. There are +! none with -O (cf. original testcase file 'pr93464.f90'). +! For -O0, see below: + +program p + character :: c(2) = 'a' + character, allocatable :: z(:) + ! { dg-note {'z' declared here} {} { target *-*-* } .-1 } + !$acc parallel + ! { 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 + ! Remark: As run-time check, required either 'c' being allocated or if(allocated(c)': + z = c + !$acc end parallel + !$omp end target + print *, z +end diff --git a/gcc/testsuite/gfortran.dg/goacc/pr93464.f90 b/gcc/testsuite/gfortran.dg/goacc/pr93464.f90 index c92f1d3..1b5ca7d 100644 --- a/gcc/testsuite/gfortran.dg/goacc/pr93464.f90 +++ b/gcc/testsuite/gfortran.dg/goacc/pr93464.f90 @@ -1,17 +1,21 @@ +! { dg-additional-options -Wuninitialized } +! ! PR fortran/93464 ! ! Contributed by G. Steinmetz +! +! Did before ICE in gfc_omp_check_optional_argument -! { dg-additional-options -Wuninitialized } +! Additionally, check for uninitialized warnings. +! Compiled with -O (as done here), no show up; +! for -O0, see testcase file 'pr93464-1.f90'. 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 } !$omp target + ! Remark: As run-time check, required either 'c' being allocated or if(allocated(c)': z = c !$acc end parallel !$omp end target |