[flang-commits] [flang] [Flang][MIF] Adding support of intrinsics with coarray argument (PR #192944)
Dan Bonachea via flang-commits
flang-commits at lists.llvm.org
Thu Apr 23 20:46:02 PDT 2026
================
@@ -2172,6 +2188,11 @@ genIntrinsicRefCore(Fortran::lower::PreparedActualArguments &loweredActuals,
const fir::IntrinsicArgumentLoweringRules *argLowering =
intrinsicEntry.getArgumentLoweringRules();
for (auto arg : llvm::enumerate(loweredActuals)) {
+ // Trying to retrieve the corank of a variable if this is a coarray
+ mlir::IntegerAttr corankAttr;
+ if (const Fortran::lower::SomeExpr *expr =
+ callContext.procRef.UnwrapArgExpr(arg.index()))
+ corankAttr = getCorankFromExpr(builder, *expr);
----------------
bonachea wrote:
Given the repeated use pattern below, this seems like it could more concisely be expressed as a lambda, something like (untested):
```suggestion
auto setCorankAttr = [&](fir::ExtendedValue exv) {
mlir::IntegerAttr corankAttr;
if (const Fortran::lower::SomeExpr *expr =
callContext.procRef.UnwrapArgExpr(arg.index()))
corankAttr = getCorankFromExpr(builder, *expr);
if (corankAttr)
fir::getBase(exv).getDefiningOp()->setAttr(fir::getCorankAttrName(),
corankAttr);
};
```
and then below in all six places currently using `corankAttr` this could be invoked as simply:
```c++
setCorankAttr(exv);
```
Of course if we drop the use of corank attribute as @jeanPerier suggests, then perhaps this code is obsolete.
https://github.com/llvm/llvm-project/pull/192944
More information about the flang-commits
mailing list