diff --git a/flang/lib/Lower/OpenACC.cpp b/flang/lib/Lower/OpenACC.cpp --- a/flang/lib/Lower/OpenACC.cpp +++ b/flang/lib/Lower/OpenACC.cpp @@ -904,10 +904,13 @@ } } else if (const auto *copyClause = std::get_if(&clause.u)) { + auto crtDataStart = dataClauseOperands.size(); genDataOperandOperations( copyClause->v, converter, semanticsContext, stmtCtx, - copyEntryOperands, mlir::acc::DataClause::acc_copy, + dataClauseOperands, mlir::acc::DataClause::acc_copy, /*structured=*/true); + copyEntryOperands.append(dataClauseOperands.begin() + crtDataStart, + dataClauseOperands.end()); } else if (const auto *copyinClause = std::get_if(&clause.u)) { genDataOperandOperationsWithModifier( &clause.u)) { + auto crtDataStart = dataClauseOperands.size(); genDataOperandOperationsWithModifier( copyoutClause, converter, semanticsContext, stmtCtx, Fortran::parser::AccDataModifier::Modifier::ReadOnly, - copyoutEntryOperands, mlir::acc::DataClause::acc_copyout, + dataClauseOperands, mlir::acc::DataClause::acc_copyout, mlir::acc::DataClause::acc_copyout_zero); + copyoutEntryOperands.append(dataClauseOperands.begin() + crtDataStart, + dataClauseOperands.end()); } else if (const auto *createClause = std::get_if(&clause.u)) { + auto crtDataStart = dataClauseOperands.size(); genDataOperandOperationsWithModifier( createClause, converter, semanticsContext, stmtCtx, - Fortran::parser::AccDataModifier::Modifier::Zero, createEntryOperands, + Fortran::parser::AccDataModifier::Modifier::Zero, dataClauseOperands, mlir::acc::DataClause::acc_create, mlir::acc::DataClause::acc_create_zero); + createEntryOperands.append(dataClauseOperands.begin() + crtDataStart, + dataClauseOperands.end()); } else if (const auto *noCreateClause = std::get_if( &clause.u)) { @@ -956,10 +965,13 @@ /*structured=*/true); } else if (const auto *attachClause = std::get_if(&clause.u)) { + auto crtDataStart = dataClauseOperands.size(); genDataOperandOperations( attachClause->v, converter, semanticsContext, stmtCtx, - attachEntryOperands, mlir::acc::DataClause::acc_attach, + dataClauseOperands, mlir::acc::DataClause::acc_attach, /*structured=*/true); + attachEntryOperands.append(dataClauseOperands.begin() + crtDataStart, + dataClauseOperands.end()); } else if (const auto *privateClause = std::get_if( &clause.u)) { @@ -975,11 +987,6 @@ } } - dataClauseOperands.append(attachEntryOperands); - dataClauseOperands.append(copyEntryOperands); - dataClauseOperands.append(copyoutEntryOperands); - dataClauseOperands.append(createEntryOperands); - // Prepare the operand segment size attribute and the operands value range. llvm::SmallVector operands; llvm::SmallVector operandSegments; diff --git a/flang/test/Lower/OpenACC/acc-parallel.f90 b/flang/test/Lower/OpenACC/acc-parallel.f90 --- a/flang/test/Lower/OpenACC/acc-parallel.f90 +++ b/flang/test/Lower/OpenACC/acc-parallel.f90 @@ -235,6 +235,13 @@ !CHECK: acc.delete accPtr(%[[CREATE_B]] : !fir.ref>) bounds(%{{.*}}, %{{.*}}) {dataClause = 7 : i64, name = "b"} !CHECK: acc.delete accPtr(%[[CREATE_C]] : !fir.ref>) bounds(%{{.*}}, %{{.*}}) {dataClause = 8 : i64, name = "c"} + !$acc parallel create(c) copy(b) create(a) + !$acc end parallel +!CHECK: %[[CREATE_C:.*]] = acc.create varPtr(%[[C]] : !fir.ref>) bounds(%{{.*}}, %{{.*}}) -> !fir.ref> {name = "c"} +!CHECK: %[[COPY_B:.*]] = acc.copyin varPtr(%[[B]] : !fir.ref>) bounds(%{{.*}}, %{{.*}}) -> !fir.ref> {dataClause = 3 : i64, name = "b"} +!CHECK: %[[CREATE_A:.*]] = acc.create varPtr(%[[A]] : !fir.ref>) bounds(%{{.*}}, %{{.*}}) -> !fir.ref> {name = "a"} +!CHECK: acc.parallel dataOperands(%[[CREATE_C]], %[[COPY_B]], %[[CREATE_A]] : !fir.ref>, !fir.ref>, !fir.ref>) { + !$acc parallel no_create(a, b) create(zero: c) !$acc end parallel