[flang-commits] [flang] [flang] Associate named constant actual arguments with their storage (PR #222986)
Eugene Epshteyn via flang-commits
flang-commits at lists.llvm.org
Mon Sep 28 18:32:51 PDT 2026
================
@@ -132,6 +132,29 @@ void CheckImplicitInterfaceArg(evaluate::ActualArgument &arg,
// F'2023 15.5.2.12p1: "Sequence association only applies when the dummy
// argument is an explicit-shape or assumed-size array."
+// Total size in bytes of a whole object for storage-sequence checks.
+// A named constant has no storage assignment (symbol.size() is zero), so
+// measure it from its type and constant extents instead.
+static std::optional<std::int64_t> ObjectTotalBytes(
+ const Symbol &symbol, evaluate::FoldingContext &foldingContext) {
+ if (std::size_t bytes{symbol.size()}) {
+ return static_cast<std::int64_t>(bytes);
+ }
+ if (const Symbol &ultimate{symbol.GetUltimate()}; IsNamedConstant(ultimate)) {
+ if (auto type{evaluate::DynamicType::From(ultimate)}) {
+ if (auto extents{
+ evaluate::GetConstantExtents(foldingContext, &ultimate)}) {
+ if (auto bytes{evaluate::ToInt64(evaluate::Fold(foldingContext,
+ type->MeasureSizeInBytes(
+ foldingContext, evaluate::GetRank(*extents) > 0)))}) {
+ return *bytes * evaluate::GetSize(*extents);
----------------
eugeneepshteyn wrote:
Good call — it did not work, and there was no test covering it. The designator folder gets bounds through `GetLBOUND`, which for an explicit lower bound other than 1 requires an explicit upper bound to prove the dimension is not empty. An implied-shape array has no explicit upper bound, so the bound came back unknown, `FoldDesignator` gave up, and both storage sequence checks were silently skipped.
Fixed in `GetLowerBoundHelper` by taking the extent from the initializer for implied-shape named constants, with `(*)`, `(0:*)` and `(0:*,*)` cases — both conforming and too-short — added to `flang/test/Semantics/call-parameter-seq-assoc.f90`.
The same gap also kept omitted-bound sections of such constants from being constant expressions, so `size(p(:))`, `ubound(p(:),1)` and array expressions over them were rejected in constant contexts. The same change fixes that, covered by a new `flang/test/Evaluate/fold-implied-shape-section.f90`. (Should this perhaps be a separate PR?)
https://github.com/llvm/llvm-project/pull/222986
More information about the flang-commits
mailing list