[flang-commits] [flang] [flang][OpenMP] Fix sections lastprivate for common blocks (PR #125504)
via flang-commits
flang-commits at lists.llvm.org
Mon Feb 3 06:19:38 PST 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-flang-fir-hlfir
Author: Leandro Lupori (luporl)
<details>
<summary>Changes</summary>
Common block handling was missing in sections' lastprivate lowering.
Fixes #<!-- -->121719
---
Full diff: https://github.com/llvm/llvm-project/pull/125504.diff
2 Files Affected:
- (modified) flang/lib/Lower/OpenMP/OpenMP.cpp (+7-1)
- (modified) flang/test/Lower/OpenMP/sections.f90 (+18-1)
``````````diff
diff --git a/flang/lib/Lower/OpenMP/OpenMP.cpp b/flang/lib/Lower/OpenMP/OpenMP.cpp
index 25595d2ea6c7d8..01ad9eff166003 100644
--- a/flang/lib/Lower/OpenMP/OpenMP.cpp
+++ b/flang/lib/Lower/OpenMP/OpenMP.cpp
@@ -2089,7 +2089,13 @@ genSectionsOp(lower::AbstractConverter &converter, lower::SymMap &symTable,
const auto &objList = std::get<ObjectList>(lastp->t);
for (const Object &object : objList) {
semantics::Symbol *sym = object.sym();
- converter.copyHostAssociateVar(*sym, &insp, /*hostIsSource=*/false);
+ if (const auto *common =
+ sym->detailsIf<semantics::CommonBlockDetails>()) {
+ for (const auto &obj : common->objects())
+ converter.copyHostAssociateVar(*obj, &insp, /*hostIsSource=*/false);
+ } else {
+ converter.copyHostAssociateVar(*sym, &insp, /*hostIsSource=*/false);
+ }
}
}
}
diff --git a/flang/test/Lower/OpenMP/sections.f90 b/flang/test/Lower/OpenMP/sections.f90
index 22879185286352..5900eef6ea2802 100644
--- a/flang/test/Lower/OpenMP/sections.f90
+++ b/flang/test/Lower/OpenMP/sections.f90
@@ -2,7 +2,7 @@
! This test checks the lowering of OpenMP sections construct with several clauses present
-! RUN: %flang_fc1 -flang-experimental-hlfir -emit-hlfir %openmp_flags %s -o - | FileCheck %s
+! RUN: %flang_fc1 -emit-hlfir %openmp_flags %s -o - | FileCheck %s
! RUN: bbc -hlfir -emit-hlfir %openmp_flags %s -o - | FileCheck %s
!CHECK: func @_QQmain() attributes {fir.bindc_name = "sample"} {
@@ -263,6 +263,23 @@ subroutine lastprivate2()
!$omp end sections
end subroutine
+!CHECK-LABEL: func @_QPlastprivate_common
+!CHECK: %[[I:.*]]:2 = hlfir.declare %{{.*}} {uniq_name = "_QFlastprivate_commonEi"} : (!fir.ref<i32>) -> (!fir.ref<i32>, !fir.ref<i32>)
+!CHECK: %[[I_PRIV:.*]]:2 = hlfir.declare %{{.*}} {uniq_name = "_QFlastprivate_commonEi"} : (!fir.ref<i32>) -> (!fir.ref<i32>, !fir.ref<i32>)
+!CHECK: omp.sections
+!CHECK: omp.section
+!CHECK: %[[TMP:.*]] = fir.load %[[I_PRIV]]#0 : !fir.ref<i32>
+!CHECK: hlfir.assign %[[TMP]] to %[[I]]#0 : i32, !fir.ref<i32>
+subroutine lastprivate_common()
+ integer :: i
+ common /com/ i
+
+ i = 1
+ !$omp sections lastprivate(/com/)
+ i = 2
+ !$omp end sections
+end subroutine
+
!CHECK-LABEL: func @_QPunstructured_sections_privatization
subroutine unstructured_sections_privatization()
!CHECK: %[[X:.*]] = fir.alloca f32 {bindc_name = "x", uniq_name = "_QFunstructured_sections_privatizationEx"}
``````````
</details>
https://github.com/llvm/llvm-project/pull/125504
More information about the flang-commits
mailing list