[flang-commits] [flang] [flang][OpenMP] Fix nested privatization of allocatable (PR #96968)
via flang-commits
flang-commits at lists.llvm.org
Thu Jun 27 14:11:25 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-flang-fir-hlfir
Author: Leandro Lupori (luporl)
<details>
<summary>Changes</summary>
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
---
Full diff: https://github.com/llvm/llvm-project/pull/96968.diff
2 Files Affected:
- (modified) flang/lib/Lower/Bridge.cpp (+1-1)
- (added) flang/test/Lower/OpenMP/task2.f90 (+33)
``````````diff
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
``````````
</details>
https://github.com/llvm/llvm-project/pull/96968
More information about the flang-commits
mailing list