Index: flang/lib/Lower/ConvertExpr.cpp =================================================================== --- flang/lib/Lower/ConvertExpr.cpp +++ flang/lib/Lower/ConvertExpr.cpp @@ -489,6 +489,18 @@ return false; } +/// Is this a call to an elemental procedure with at least one argument in +/// parentheses? +static bool +isElementalProcWithParenArgs(const Fortran::evaluate::ProcedureRef &procRef) { + if (procRef.IsElemental()) + for (const std::optional &arg : + procRef.arguments()) + if (arg && isParenthesizedVariable(*arg.value().UnwrapExpr())) + return true; + return false; +} + /// Some auxiliary data for processing initialization in ScalarExprLowering /// below. This is currently used for generating dense attributed global /// arrays. @@ -3915,10 +3927,17 @@ ael.lowerElementalSubroutine(call); } - // TODO: See the comment in genarr(const Fortran::lower::Parentheses&). - // This is skipping generation of copy-in/copy-out code for analysis that is - // required when arguments are in parentheses. void lowerElementalSubroutine(const Fortran::lower::SomeExpr &call) { + assert(isElementalProcWithArrayArgs(call) && + "no array argument in elemental call"); + if (const auto *procRef = + std::get_if(&call.u)) { + if (isElementalProcWithParenArgs(*procRef)) { + // TODO: All array arguments with INTENT(OUT) or INTENT(INOUT) should + // use array_modify and array_merge_store ops. + TODO(getLoc(), "parentheses on argument in elemental call"); + } + } auto f = genarr(call); llvm::SmallVector shape = genIterationShape(); auto [iterSpace, insPt] = genImplicitLoops(shape, /*innerArg=*/{}); @@ -5147,13 +5166,6 @@ template CC genarr(const Fortran::evaluate::Parentheses &x) { mlir::Location loc = getLoc(); - if (isReferentiallyOpaque()) { - // Context is a call argument in, for example, an elemental procedure - // call. TODO: all array arguments should use array_load, array_access, - // array_amend, and INTENT(OUT), INTENT(INOUT) arguments should have - // array_merge_store ops. - TODO(loc, "parentheses on argument in elemental call"); - } auto f = genarr(x.left()); return [=](IterSpace iters) -> ExtValue { auto val = f(iters);