[PATCH] Fortran, Allow task-reduction allocatable scalars without, outer ref [PR102596]
Jerry D <[email protected]>
| Newsgroups | gmane.comp.gcc.patches,gmane.comp.gcc.fortran |
|---|---|
| Message-ID | <[email protected]> |
Note: This is a regression fix. The attached patch regression tested on x86_64. This one is fairly simple. I will commit shortly. Regards, Jerry fortran: Allow task-reduction allocatable scalars without outer ref [PR102596] OpenMP task reduction lowering can call gfc_omp_clause_default_ctor for an allocatable scalar with outer == NULL_TREE. That is valid for scalar allocatables that only need fresh storage allocation and do not need a copied descriptor or allocatable-component walk. The Fortran hook asserted unconditionally on outer != NULL_TREE, so reduction(task, +:r) with an allocatable scalar ICEd during omplower. Fix this by requiring outer only for the cases that actually use it: descriptor-based allocatables and types with allocatable components. Keep the assertion for those cases and allow NULL outer for plain scalar allocatables. Add a regression test for the allocatable task-reduction case. gcc/fortran/ChangeLog: PR fortran/102596 * trans-openmp.cc (gfc_omp_clause_default_ctor): Only require an outer reference when the constructor path actually uses it. gcc/testsuite/ChangeLog: PR fortran/102596 * gfortran.dg/pr102596.f90: New test. Signed-off-by: Christopher Albert <[email protected]>
pr102596.diff
(text/x-patch, 2.5 KB)
From aba89bd758f1ddb3d42ca41260b872198ccdc511 Mon Sep 17 00:00:00 2001 From: Christopher Albert <[email protected]> Date: Tue, 10 Mar 2026 19:16:24 +0100 Subject: [PATCH] fortran: Allow task-reduction allocatable scalars without outer ref [PR102596] OpenMP task reduction lowering can call gfc_omp_clause_default_ctor for an allocatable scalar with outer == NULL_TREE. That is valid for scalar allocatables that only need fresh storage allocation and do not need a copied descriptor or allocatable-component walk. The Fortran hook asserted unconditionally on outer != NULL_TREE, so reduction(task, +:r) with an allocatable scalar ICEd during omplower. Fix this by requiring outer only for the cases that actually use it: descriptor-based allocatables and types with allocatable components. Keep the assertion for those cases and allow NULL outer for plain scalar allocatables. Add a regression test for the allocatable task-reduction case. gcc/fortran/ChangeLog: PR fortran/102596 * trans-openmp.cc (gfc_omp_clause_default_ctor): Only require an outer reference when the constructor path actually uses it. gcc/testsuite/ChangeLog: PR fortran/102596 * gfortran.dg/pr102596.f90: New test. Signed-off-by: Christopher Albert <[email protected]> --- gcc/fortran/trans-openmp.cc | 5 ++++- gcc/testsuite/gfortran.dg/pr102596.f90 | 13 +++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gfortran.dg/pr102596.f90 diff --git a/gcc/fortran/trans-openmp.cc b/gcc/fortran/trans-openmp.cc index 3dd4cf272e5..2842a0c191c 100644 --- a/gcc/fortran/trans-openmp.cc +++ b/gcc/fortran/trans-openmp.cc @@ -815,7 +815,10 @@ gfc_omp_clause_default_ctor (tree clause, tree decl, tree outer) return NULL_TREE; } - gcc_assert (outer != NULL_TREE); + gcc_assert (outer != NULL_TREE + || (!GFC_DESCRIPTOR_TYPE_P (type) + && !gfc_has_alloc_comps (type, OMP_CLAUSE_DECL (clause), + false))); /* Allocatable arrays and scalars in PRIVATE clauses need to be set to "not currently allocated" allocation status if outer diff --git a/gcc/testsuite/gfortran.dg/pr102596.f90 b/gcc/testsuite/gfortran.dg/pr102596.f90 new file mode 100644 index 00000000000..b8c3b2f72d7 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/pr102596.f90 @@ -0,0 +1,13 @@ +! { dg-do compile } +! { dg-additional-options "-fopenmp" } + +program p + integer, allocatable :: r + + allocate (r) + r = 0 + + !$omp target parallel reduction(task, +:r) + r = r + 1 + !$omp end target parallel +end -- 2.53.0