Skip to content

Commit 6fc66d3

Browse files
authored
[flang][OpenMP] Fix sections lastprivate for common blocks (#125504)
Common block handling was missing in sections' lastprivate lowering. Fixes #121719
1 parent 7ece824 commit 6fc66d3

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

flang/lib/Lower/OpenMP/OpenMP.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2089,7 +2089,13 @@ genSectionsOp(lower::AbstractConverter &converter, lower::SymMap &symTable,
20892089
const auto &objList = std::get<ObjectList>(lastp->t);
20902090
for (const Object &object : objList) {
20912091
semantics::Symbol *sym = object.sym();
2092-
converter.copyHostAssociateVar(*sym, &insp, /*hostIsSource=*/false);
2092+
if (const auto *common =
2093+
sym->detailsIf<semantics::CommonBlockDetails>()) {
2094+
for (const auto &obj : common->objects())
2095+
converter.copyHostAssociateVar(*obj, &insp, /*hostIsSource=*/false);
2096+
} else {
2097+
converter.copyHostAssociateVar(*sym, &insp, /*hostIsSource=*/false);
2098+
}
20932099
}
20942100
}
20952101
}

flang/test/Lower/OpenMP/sections.f90

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
! This test checks the lowering of OpenMP sections construct with several clauses present
44

5-
! RUN: %flang_fc1 -flang-experimental-hlfir -emit-hlfir %openmp_flags %s -o - | FileCheck %s
5+
! RUN: %flang_fc1 -emit-hlfir %openmp_flags %s -o - | FileCheck %s
66
! RUN: bbc -hlfir -emit-hlfir %openmp_flags %s -o - | FileCheck %s
77

88
!CHECK: func @_QQmain() attributes {fir.bindc_name = "sample"} {
@@ -263,6 +263,23 @@ subroutine lastprivate2()
263263
!$omp end sections
264264
end subroutine
265265

266+
!CHECK-LABEL: func @_QPlastprivate_common
267+
!CHECK: %[[I:.*]]:2 = hlfir.declare %{{.*}} {uniq_name = "_QFlastprivate_commonEi"} : (!fir.ref<i32>) -> (!fir.ref<i32>, !fir.ref<i32>)
268+
!CHECK: %[[I_PRIV:.*]]:2 = hlfir.declare %{{.*}} {uniq_name = "_QFlastprivate_commonEi"} : (!fir.ref<i32>) -> (!fir.ref<i32>, !fir.ref<i32>)
269+
!CHECK: omp.sections
270+
!CHECK: omp.section
271+
!CHECK: %[[TMP:.*]] = fir.load %[[I_PRIV]]#0 : !fir.ref<i32>
272+
!CHECK: hlfir.assign %[[TMP]] to %[[I]]#0 : i32, !fir.ref<i32>
273+
subroutine lastprivate_common()
274+
integer :: i
275+
common /com/ i
276+
277+
i = 1
278+
!$omp sections lastprivate(/com/)
279+
i = 2
280+
!$omp end sections
281+
end subroutine
282+
266283
!CHECK-LABEL: func @_QPunstructured_sections_privatization
267284
subroutine unstructured_sections_privatization()
268285
!CHECK: %[[X:.*]] = fir.alloca f32 {bindc_name = "x", uniq_name = "_QFunstructured_sections_privatizationEx"}

0 commit comments

Comments
 (0)