[flang-commits] [flang] [flang][OpenMP] Put taskgroup in a new scope (PR #144122)
Leandro Lupori via flang-commits
flang-commits at lists.llvm.org
Fri Jun 13 10:05:26 PDT 2025
https://github.com/luporl created https://github.com/llvm/llvm-project/pull/144122
Although taskgroup is a privatizing construct, because of
task_reduction clause, a new scope was not being created for it.
This could cause an extra privatization of variables when
taskgroup was lowered, because its scope would be the same as of
the parent privatizing construct.
This fixes regressions in tests 1052_0201 and 1052_0205, from
Fujitsu testsuite.
This issue didn't happen before because implicit symbols were
being created in a different way before #142154.
>From 0b8b37b81b1283560234580552fea14030dc3b8d Mon Sep 17 00:00:00 2001
From: Leandro Lupori <leandro.lupori at linaro.org>
Date: Fri, 13 Jun 2025 13:45:48 -0300
Subject: [PATCH] [flang][OpenMP] Put taskgroup in a new scope
Although taskgroup is a privatizing construct, because of
task_reduction clause, a new scope was not being created for it.
This could cause an extra privatization of variables when
taskgroup was lowered, because its scope would be the same as of
the parent privatizing construct.
This fixes regressions in tests 1052_0201 and 1052_0205, from
Fujitsu testsuite.
This issue didn't happen before because implicit symbols were
being created in a different way before #142154.
---
flang/lib/Semantics/resolve-names.cpp | 1 -
flang/test/Lower/OpenMP/taskgroup02.f90 | 32 +++++++++++++++++++++++++
2 files changed, 32 insertions(+), 1 deletion(-)
create mode 100644 flang/test/Lower/OpenMP/taskgroup02.f90
diff --git a/flang/lib/Semantics/resolve-names.cpp b/flang/lib/Semantics/resolve-names.cpp
index 7db447aee0026..8aa137f603b3d 100644
--- a/flang/lib/Semantics/resolve-names.cpp
+++ b/flang/lib/Semantics/resolve-names.cpp
@@ -1729,7 +1729,6 @@ bool OmpVisitor::NeedsScope(const parser::OpenMPBlockConstruct &x) {
switch (beginDir.v) {
case llvm::omp::Directive::OMPD_master:
case llvm::omp::Directive::OMPD_ordered:
- case llvm::omp::Directive::OMPD_taskgroup:
return false;
default:
return true;
diff --git a/flang/test/Lower/OpenMP/taskgroup02.f90 b/flang/test/Lower/OpenMP/taskgroup02.f90
new file mode 100644
index 0000000000000..1e996a030c23a
--- /dev/null
+++ b/flang/test/Lower/OpenMP/taskgroup02.f90
@@ -0,0 +1,32 @@
+! RUN: %flang_fc1 -emit-hlfir -fopenmp -o - %s 2>&1 | FileCheck %s
+
+! Check that variables are not privatized twice when TASKGROUP is used.
+
+!CHECK-LABEL: func.func @_QPsub() {
+!CHECK: omp.parallel {
+!CHECK: %[[PAR_I:.*]]:2 = hlfir.declare %{{.*}} {uniq_name = "_QFsubEi"}
+!CHECK: omp.master {
+!CHECK: omp.taskgroup {
+!CHECK-NEXT: omp.task private(@_QFsubEi_firstprivate_i32 %[[PAR_I]]#0 -> %[[TASK_I:.*]] : !fir.ref<i32>) {
+!CHECK: %[[TASK_I_DECL:.*]]:2 = hlfir.declare %[[TASK_I]] {uniq_name = "_QFsubEi"}
+!CHECK: }
+!CHECK: }
+!CHECK: }
+!CHECK: }
+
+subroutine sub()
+ integer, dimension(10) :: a
+ integer :: i
+
+ !$omp parallel
+ !$omp master
+ do i=1,10
+ !$omp taskgroup
+ !$omp task shared(a)
+ a(i) = 1
+ !$omp end task
+ !$omp end taskgroup
+ end do
+ !$omp end master
+ !$omp end parallel
+end subroutine
More information about the flang-commits
mailing list