diff --git a/flang/lib/Lower/OpenMP/DataSharingProcessor.cpp b/flang/lib/Lower/OpenMP/DataSharingProcessor.cpp index b88454c45da85..7eec598645eac 100644 --- a/flang/lib/Lower/OpenMP/DataSharingProcessor.cpp +++ b/flang/lib/Lower/OpenMP/DataSharingProcessor.cpp @@ -67,6 +67,8 @@ void DataSharingProcessor::processStep1( void DataSharingProcessor::processStep2(mlir::Operation *op, bool isLoop) { // 'sections' lastprivate is handled by genOMP() + if (mlir::isa(op)) + return; if (!mlir::isa(op)) { mlir::OpBuilder::InsertionGuard guard(firOpBuilder); copyLastPrivatize(op); diff --git a/flang/lib/Lower/OpenMP/OpenMP.cpp b/flang/lib/Lower/OpenMP/OpenMP.cpp index f099028c23323..96c7aee865f7d 100644 --- a/flang/lib/Lower/OpenMP/OpenMP.cpp +++ b/flang/lib/Lower/OpenMP/OpenMP.cpp @@ -2162,6 +2162,7 @@ genSectionsOp(lower::AbstractConverter &converter, lower::SymMap &symTable, OpWithBodyGenInfo(converter, symTable, semaCtx, loc, nestedEval, llvm::omp::Directive::OMPD_section) .setClauses(§ionQueue.begin()->clauses) + .setDataSharingProcessor(&dsp) .setEntryBlockArgs(&args), sectionQueue, sectionQueue.begin()); } diff --git a/flang/test/Lower/OpenMP/sections-predetermined-private.f90 b/flang/test/Lower/OpenMP/sections-predetermined-private.f90 new file mode 100644 index 0000000000000..9c2e2e127aa78 --- /dev/null +++ b/flang/test/Lower/OpenMP/sections-predetermined-private.f90 @@ -0,0 +1,34 @@ +! RUN: %flang_fc1 -fopenmp -emit-hlfir -o - %s | FileCheck %s + +!$omp parallel sections +!$omp section + do i = 1, 2 + end do +!$omp section + do i = 1, 2 + end do +!$omp end parallel sections +end +! CHECK-LABEL: func.func @_QQmain() { +! CHECK: omp.parallel { +! CHECK: %[[VAL_3:.*]] = fir.alloca i32 {bindc_name = "i", pinned} +! CHECK: %[[VAL_4:.*]]:2 = hlfir.declare %[[VAL_3]] {uniq_name = "_QFEi"} : (!fir.ref) -> (!fir.ref, !fir.ref) +! CHECK: omp.sections { +! CHECK: omp.section { +! CHECK: %[[VAL_11:.*]]:2 = fir.do_loop %[[VAL_12:.*]] = %{{.*}} to %{{.*}} step %{{.*}} iter_args(%{{.*}} = %{{.*}} -> (index, i32) { +! CHECK: } +! CHECK: fir.store %[[VAL_11]]#1 to %[[VAL_4]]#0 : !fir.ref +! CHECK: omp.terminator +! CHECK: } +! CHECK: omp.section { +! CHECK: %[[VAL_25:.*]]:2 = fir.do_loop %[[VAL_26:.*]] = %{{.*}} to %{{.*}} step %{{.*}} iter_args(%{{.*}} = %{{.*}}) -> (index, i32) { +! CHECK: } +! CHECK: fir.store %[[VAL_25]]#1 to %[[VAL_4]]#0 : !fir.ref +! CHECK: omp.terminator +! CHECK: } +! CHECK: omp.terminator +! CHECK: } +! CHECK: omp.terminator +! CHECK: } +! CHECK: return +! CHECK: }