[flang-commits] [flang] [flang] Fix sequence association for PARAMETER array elements (PR #187348)
Eugene Epshteyn via flang-commits
flang-commits at lists.llvm.org
Wed Mar 18 13:00:26 PDT 2026
================
@@ -5184,7 +5184,29 @@ MaybeExpr ArgumentAnalyzer::AnalyzeExprOrWholeAssumedSizeArray(
}
}
auto restorer{context_.AllowNullPointer()};
- return context_.Analyze(expr);
+ MaybeExpr result{context_.Analyze(expr)};
+ // If the expression is a subscripted named constant array (PARAMETER array
+ // element), preserve the Designator<ArrayRef> form rather than returning the
+ // folded scalar constant. Sequence association requires a designator with
+ // an array element subscript (F'2023 15.5.2.5p14); constant folding of
+ // PARAMETER array elements loses this structure.
+ // Note: Analyze(expr) may have converted a FunctionReference to a Designator
+ // in the parse tree (via CheckFuncRefToArrayElement), so check for
+ // ArrayElement only after Analyze(expr) has run.
+ if (isProcedureCall_ && result && result->Rank() == 0) {
+ if (const auto *ae{parser::Unwrap<parser::ArrayElement>(expr)}) {
+ const auto &baseName{parser::GetLastName(ae->Base())};
----------------
eugeneepshteyn wrote:
Thank you, I got confused between "rightmost Name" and "leftmost Name".
I'll also add a test for `x%y(1)` case.
https://github.com/llvm/llvm-project/pull/187348
More information about the flang-commits
mailing list