[flang-commits] [flang] [flang][OpenMP] Fix nested privatization of allocatable (PR #96968)

Leandro Lupori via flang-commits flang-commits at lists.llvm.org
Fri Jun 28 06:42:03 PDT 2024


https://github.com/luporl updated https://github.com/llvm/llvm-project/pull/96968

>From 17310f2b5cf836abd7c84218dbb57ce61d7fcd76 Mon Sep 17 00:00:00 2001
From: Leandro Lupori <leandro.lupori at linaro.org>
Date: Thu, 27 Jun 2024 17:58:50 -0300
Subject: [PATCH 1/2] [flang][OpenMP] Fix nested privatization of allocatable

In nested constructs where a given variable is privatized more than
once, using the default clause, the innermost host association symbol
will point to the previous host association symbol.
Such symbol lacks the allocatable attribute and can't be used to
generate the type of the symbol to be cloned. Use the ultimate
symbol instead.

Fixes #85594
---
 flang/lib/Lower/Bridge.cpp        |  2 +-
 flang/test/Lower/OpenMP/task2.f90 | 33 +++++++++++++++++++++++++++++++
 2 files changed, 34 insertions(+), 1 deletion(-)
 create mode 100644 flang/test/Lower/OpenMP/task2.f90

diff --git a/flang/lib/Lower/Bridge.cpp b/flang/lib/Lower/Bridge.cpp
index 50f58843ec70b..d4c5053927539 100644
--- a/flang/lib/Lower/Bridge.cpp
+++ b/flang/lib/Lower/Bridge.cpp
@@ -625,7 +625,7 @@ class FirConverter : public Fortran::lower::AbstractConverter {
     const auto *details = sym.detailsIf<Fortran::semantics::HostAssocDetails>();
     assert(details && "No host-association found");
     const Fortran::semantics::Symbol &hsym = details->symbol();
-    mlir::Type hSymType = genType(hsym);
+    mlir::Type hSymType = genType(hsym.GetUltimate());
     Fortran::lower::SymbolBox hsb =
         lookupSymbol(hsym, /*symMap=*/nullptr, /*forceHlfirBase=*/true);
 
diff --git a/flang/test/Lower/OpenMP/task2.f90 b/flang/test/Lower/OpenMP/task2.f90
new file mode 100644
index 0000000000000..a2df046d5cd2a
--- /dev/null
+++ b/flang/test/Lower/OpenMP/task2.f90
@@ -0,0 +1,33 @@
+!RUN: %flang_fc1 -emit-hlfir %openmp_flags %s -o - | FileCheck %s
+
+!CHECK-LABEL: func @_QPomp_task_nested_allocatable_firstprivate
+subroutine omp_task_nested_allocatable_firstprivate
+  integer, allocatable :: a(:)
+
+  allocate(a(7))
+  a = 10
+
+!CHECK:       %[[A:.*]]:2 = hlfir.declare %{{.*}} {fortran_attrs = #fir.var_attrs<allocatable>,
+!CHECK-SAME:    uniq_name = "_QFomp_task_nested_allocatable_firstprivateEa"} :
+!CHECK-SAME:    (!fir.ref<!fir.box<!fir.heap<!fir.array<?xi32>>>>) ->
+!CHECK-SAME:    (!fir.ref<!fir.box<!fir.heap<!fir.array<?xi32>>>>, !fir.ref<!fir.box<!fir.heap<!fir.array<?xi32>>>>)
+!CHECK:       omp.task {
+  !$omp task default(firstprivate)
+!CHECK:         omp.task {
+!CHECK:           %[[PRIV_A:.*]]:2 = hlfir.declare %{{.*}} {fortran_attrs = #fir.var_attrs<allocatable>,
+!CHECK-SAME:        uniq_name = "_QFomp_task_nested_allocatable_firstprivateEa"} :
+!CHECK-SAME:        (!fir.ref<!fir.box<!fir.heap<!fir.array<?xi32>>>>) ->
+!CHECK-SAME:        (!fir.ref<!fir.box<!fir.heap<!fir.array<?xi32>>>>, !fir.ref<!fir.box<!fir.heap<!fir.array<?xi32>>>>)
+!CHECK:           %[[PRIV_A_BOX:.*]] = fir.load %[[PRIV_A]]#0 : !fir.ref<!fir.box<!fir.heap<!fir.array<?xi32>>>>
+!CHECK:           fir.if %{{.*}} {
+!CHECK:             %[[TEMP:.*]] = fir.load %[[A]]#0 : !fir.ref<!fir.box<!fir.heap<!fir.array<?xi32>>>>
+!CHECK:             hlfir.assign %[[TEMP]] to %[[PRIV_A_BOX]] temporary_lhs :
+!CHECK-SAME:          !fir.box<!fir.heap<!fir.array<?xi32>>>, !fir.box<!fir.heap<!fir.array<?xi32>>>
+!CHECK:           }
+    !$omp task default(firstprivate)
+      a = 2
+!CHECK:         }
+    !$omp end task
+!CHECK:       }
+  !$omp end task
+end subroutine

>From 5eabdbe9d83aa5005d317126cd1eb7b2fa11ede0 Mon Sep 17 00:00:00 2001
From: Leandro Lupori <leandro.lupori at linaro.org>
Date: Fri, 28 Jun 2024 10:41:32 -0300
Subject: [PATCH 2/2] Fix regression test

---
 flang/test/Lower/OpenMP/task2.f90 | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/flang/test/Lower/OpenMP/task2.f90 b/flang/test/Lower/OpenMP/task2.f90
index a2df046d5cd2a..ce491d95e9397 100644
--- a/flang/test/Lower/OpenMP/task2.f90
+++ b/flang/test/Lower/OpenMP/task2.f90
@@ -1,4 +1,4 @@
-!RUN: %flang_fc1 -emit-hlfir %openmp_flags %s -o - | FileCheck %s
+!RUN: %flang_fc1 -emit-hlfir -fopenmp %s -o - | FileCheck %s
 
 !CHECK-LABEL: func @_QPomp_task_nested_allocatable_firstprivate
 subroutine omp_task_nested_allocatable_firstprivate



More information about the flang-commits mailing list