[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 Oct 14 01:13:09 PDT 2026


================
@@ -1427,7 +1444,8 @@ Expr<Type<TypeCategory::Integer, KIND>> FoldIntrinsicFunction(
           return result.value;
         }));
   } else if (name == "size") {
-    if (auto shape{GetContextFreeShape(context, args[0])}) {
+    if (auto shape{GetContextFreeShape(context, args[0])};
----------------
MattPD wrote:

When `shape && !ShapeHasUntaggedRankOneBoundElement(shape)` is false, `size` is neither folded nor checked, because `CheckDimArg` runs only when the condition is true. This affects both valid and invalid code.

This valid module is now rejected with `Value of named constant 'count' (size(a)) cannot be computed as a constant value`. At the previous PR head 14764c2f, `count` is 12:

```fortran
module constant_minimal
  implicit none
  real :: a(0:[2, 3])
  integer, parameter :: count = size(a)
end module
```

This invalid subroutine is now accepted without diagnostics. At 14764c2f, all three `DIM` values are diagnosed:

```fortran
subroutine invalid_size_nonunit(n)
  implicit none
  integer, intent(in) :: n(2)
  real :: a(0:n)
  print *, size(a, 9)
  print *, size(a, 2147483648_8)
  print *, size(a, 0)
end subroutine
```

Could `DIM` validation run independently, with the condition on rank-one bound elements applied to the folded extents?

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


More information about the flang-commits mailing list