From 1860c031781bd8c858e9305d92f3e0e016488bd3 Mon Sep 17 00:00:00 2001 From: Thirumalai-Shaktivel Date: Mon, 7 Oct 2024 10:46:08 +0000 Subject: [PATCH 1/2] [Flang][OpenMP] Make a private copy for the common block variables in copyin clause Issue: Incorrect execution result when common block name is specified in copyin clause --- flang/lib/Lower/Bridge.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/flang/lib/Lower/Bridge.cpp b/flang/lib/Lower/Bridge.cpp index 0894a5903635e..58c2d0c2a209e 100644 --- a/flang/lib/Lower/Bridge.cpp +++ b/flang/lib/Lower/Bridge.cpp @@ -921,13 +921,20 @@ class FirConverter : public Fortran::lower::AbstractConverter { std::function insertSymbols = [&](const Fortran::semantics::Symbol &oriSymbol, bool collectSymbol) { - if (collectSymbol && oriSymbol.test(flag)) + if (collectSymbol && oriSymbol.test(flag)) { symbolSet.insert(&oriSymbol); - else if (checkHostAssociatedSymbols) + } else if (const auto *commonDetails = + oriSymbol.detailsIf< + Fortran::semantics::CommonBlockDetails>()) { + for (const auto &mem : commonDetails->objects()) + if (collectSymbol && mem->test(flag)) + symbolSet.insert(&(*mem).GetUltimate()); + } else if (checkHostAssociatedSymbols) { if (const auto *details{ oriSymbol .detailsIf()}) insertSymbols(details->symbol(), true); + } }; insertSymbols(sym, collectSymbols); }; From ee6562f133e4f41e0b089f8535efdcb559fe537c Mon Sep 17 00:00:00 2001 From: Thirumalai-Shaktivel Date: Mon, 7 Oct 2024 10:48:01 +0000 Subject: [PATCH 2/2] [Test] Add a test --- flang/test/Lower/OpenMP/copyin.f90 | 42 ++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/flang/test/Lower/OpenMP/copyin.f90 b/flang/test/Lower/OpenMP/copyin.f90 index b1c6b9420f4c4..6566158d71edd 100644 --- a/flang/test/Lower/OpenMP/copyin.f90 +++ b/flang/test/Lower/OpenMP/copyin.f90 @@ -450,3 +450,45 @@ subroutine allocatable2() a = 1 !$omp end parallel end subroutine + +! CHECK-LABEL: func.func @_QPcommon_3() { +! [...] +! CHECK: omp.parallel { +! CHECK: %[[VAL_22:.*]] = omp.threadprivate %[[VAL_0:.*]] : !fir.ref> -> !fir.ref> +! CHECK: %[[VAL_23:.*]] = fir.convert %[[VAL_22:.*]] : (!fir.ref>) -> !fir.ref> +! CHECK: %[[VAL_24:.*]] = arith.constant 0 : index +! CHECK: %[[VAL_25:.*]] = fir.coordinate_of %[[VAL_23:.*]], %[[VAL_24:.*]] : (!fir.ref>, index) -> !fir.ref +! CHECK: %[[VAL_26:.*]] = fir.convert %[[VAL_25:.*]] : (!fir.ref) -> !fir.ref +! CHECK: %[[VAL_27:.*]]:2 = hlfir.declare %[[VAL_26:.*]] {uniq_name = "_QFcommon_3Ex"} : (!fir.ref) -> (!fir.ref, !fir.ref) +! CHECK: %[[VAL_28:.*]] = fir.convert %[[VAL_22:.*]] : (!fir.ref>) -> !fir.ref> +! CHECK: %[[VAL_29:.*]] = arith.constant 4 : index +! CHECK: %[[VAL_30:.*]] = fir.coordinate_of %[[VAL_28:.*]], %[[VAL_29:.*]] : (!fir.ref>, index) -> !fir.ref +! CHECK: %[[VAL_31:.*]] = fir.convert %[[VAL_30:.*]] : (!fir.ref) -> !fir.ref +! CHECK: %[[VAL_32:.*]]:2 = hlfir.declare %[[VAL_31:.*]] {uniq_name = "_QFcommon_3Ey"} : (!fir.ref) -> (!fir.ref, !fir.ref) +! CHECK: %[[VAL_33:.*]] = fir.convert %[[VAL_22:.*]] : (!fir.ref>) -> !fir.ref> +! CHECK: %[[VAL_34:.*]] = arith.constant 8 : index +! CHECK: %[[VAL_35:.*]] = fir.coordinate_of %[[VAL_33:.*]], %[[VAL_34:.*]] : (!fir.ref>, index) -> !fir.ref +! CHECK: %[[VAL_36:.*]] = fir.convert %[[VAL_35:.*]] : (!fir.ref) -> !fir.ref>> +! CHECK: %[[VAL_37:.*]]:2 = hlfir.declare %[[VAL_36:.*]] {fortran_attrs = #fir.var_attrs, uniq_name = "_QFcommon_3Earr"} : (!fir.ref>>) -> (!fir.ref>>, !fir.ref>>) +! CHECK: %[[VAL_38:.*]] = fir.load %[[VAL_16:.*]]#0 : !fir.ref +! CHECK: hlfir.assign %[[VAL_38:.*]] to %[[VAL_27:.*]]#0 : i32, !fir.ref +! CHECK: %[[VAL_39:.*]] = fir.load %[[VAL_21:.*]]#0 : !fir.ref +! CHECK: hlfir.assign %[[VAL_39:.*]] to %[[VAL_32:.*]]#0 : i32, !fir.ref +! CHECK: %[[VAL_40:.*]] = fir.load %[[VAL_11:.*]]#0 : !fir.ref>> +! CHECK: fir.store %[[VAL_40:.*]] to %[[VAL_37:.*]]#0 : !fir.ref>> +! CHECK: omp.barrier +! CHECK: omp.terminator +! CHECK: } +! CHECK: return +! CHECK: } + +subroutine common_3() + integer :: x, y + integer, pointer :: arr + common /c3/ x, y, arr + !$omp threadprivate(/c3/) + + !$omp parallel copyin(/c3/) + call sub_3() + !$omp end parallel +end subroutine