[flang-commits] [flang] [flang][MIF] Adding common features related to coarray (PR #215576)

Dan Bonachea via flang-commits flang-commits at lists.llvm.org
Tue Aug 11 18:50:48 PDT 2026


================
@@ -263,6 +263,34 @@ void Fortran::lower::genFormTeamStatement(
 // COARRAY utils
 //===----------------------------------------------------------------------===//
 
+/// Generates a vector of cosubscripts from CoarrayRef
+mlir::SmallVector<mlir::Value>
+Fortran::lower::getCosubscripts(Fortran::lower::AbstractConverter &converter,
+                                mlir::Location loc,
+                                const Fortran::evaluate::CoarrayRef &expr) {
+  fir::FirOpBuilder &builder = converter.getFirOpBuilder();
+  Fortran::lower::StatementContext stmtCtx;
+  mlir::SmallVector<mlir::Value> cosubscripts;
+
+  // Creation of the cosubscripts vector
+  mlir::Type i64Ty = builder.getI64Type();
+  unsigned corank = expr.cosubscript().size();
+  for (unsigned dim = 0; dim < corank; ++dim) {
+    auto image = ToInt64(expr.cosubscript()[dim]);
+    mlir::Value idx;
+    if (image.has_value())
+      idx = builder.createIntegerConstant(loc, i64Ty, image.value());
----------------
bonachea wrote:

Minor: Misleading variable name

```suggestion
    auto cosub = ToInt64(expr.cosubscript()[dim]);
    mlir::Value idx;
    if (cosub.has_value())
      idx = builder.createIntegerConstant(loc, i64Ty, cosub.value());
```

https://github.com/llvm/llvm-project/pull/215576


More information about the flang-commits mailing list