[flang-commits] [flang] [flang][Lower] Implement lowering for new expression kind used in explicit-shape-bounds-spec (PR #215403)

via flang-commits flang-commits at lists.llvm.org
Wed Aug 12 02:01:16 PDT 2026


================
@@ -1865,7 +1865,23 @@ class HlfirBuilder {
 
   hlfir::EntityWithAttributes
   gen(const Fortran::evaluate::RankOneBoundElement &x) {
-    TODO(getLoc(), "rank-1 bound element lowering");
+    mlir::Location loc = getLoc();
+    auto &builder = getBuilder();
+    using ResTy = Fortran::evaluate::RankOneBoundElement::Result;
+    mlir::Type resultType =
+        getConverter().genType(ResTy::category, ResTy::kind);
+    // Evaluate the rank-1 base expression.
+    Fortran::lower::SomeExpr someExpr{Fortran::evaluate::AsGenericExpr(
+        Fortran::evaluate::Expr<Fortran::evaluate::SomeInteger>{
+            Fortran::common::Clone(x.base())})};
+    hlfir::Entity baseArray{Fortran::lower::convertExprToHLFIR(
----------------
MattPD wrote:

In `real :: a(mb(n))`, the pure function `mb` returns `integer :: r(3)`. `RankOneBoundElement` lowering evaluates `mb(n)` three times and creates three result temporaries. All three calls remain in the LLVM IR at `-O2`. Could lowering evaluate `mb(n)` once per declaration and reuse the result for every bound element?

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


More information about the flang-commits mailing list