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 @@ -1054,10 +1054,13 @@ genIfClause(converter, clauseLocation, ifClause, ifCond, stmtCtx); } 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::Zero, - copyoutEntryOperands, mlir::acc::DataClause::acc_copyout, + Fortran::parser::AccDataModifier::Modifier::Zero, 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)) { @@ -1106,18 +1115,16 @@ /*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()); } } - 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-data.f90 b/flang/test/Lower/OpenACC/acc-data.f90 --- a/flang/test/Lower/OpenACC/acc-data.f90 +++ b/flang/test/Lower/OpenACC/acc-data.f90 @@ -96,6 +96,12 @@ ! 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 data create(c) copy(b) create(a) + !$acc end data +!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.data dataOperands(%[[CREATE_C]], %[[COPY_B]], %[[CREATE_A]] : !fir.ref>, !fir.ref>, !fir.ref>) { !$acc data no_create(a, b) create(zero: c) !$acc end data