-
Notifications
You must be signed in to change notification settings - Fork 14k
[flang][OpenMP] Fix sections lastprivate for common blocks #125504
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Common block handling was missing in sections' lastprivate lowering. Fixes llvm#121719
@llvm/pr-subscribers-flang-openmp @llvm/pr-subscribers-flang-fir-hlfir Author: Leandro Lupori (luporl) ChangesCommon block handling was missing in sections' lastprivate lowering. Fixes #121719 Full diff: https://github.com/llvm/llvm-project/pull/125504.diff 2 Files Affected:
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"}
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
I was surprised this is allowed by the standard but it appears it is.
Common block handling was missing in sections' lastprivate lowering. Fixes llvm#121719
Common block handling was missing in sections' lastprivate lowering.
Fixes #121719