[flang-commits] [flang] [flang] Don't evaluate initializers for arrays with invalid rank (PR #171163)
Leandro Lupori via flang-commits
flang-commits at lists.llvm.org
Tue Dec 9 12:17:21 PST 2025
================
@@ -9209,6 +9209,11 @@ bool DeclarationVisitor::CheckNonPointerInitialization(
void DeclarationVisitor::NonPointerInitialization(
const parser::Name &name, const parser::ConstantExpr &constExpr) {
+ // Don't evaluate initializers for arrays with a rank greater than the
----------------
luporl wrote:
It would be better, but moving this check from `check-declarations.cpp` to `resolve-names.cpp` doesn't seem straightforward.
It's also necessary to skip evaluating initializers in `ResolveSpecificationParts()`, that happens early, before all declarations have been processed. It can't handle cases like this:
```f90
real :: c
dimension :: c(1,1,1,1,1,1,1,1,1,1,1,1,1,1)
codimension :: c[1,*]
```
I considered writing a function that could be used in both `ResolveSpecificationParts()` and `FinishSpecificationParts()`, but then I realized array specifications may appear in several parser constructs. I don't know what would be a good way to perform the job of `CheckObjectEntity()`, that checks all symbols with `ObjectEntityDetails`, in `resolve-names.cpp`.
So, instead, I just added a `CheckRank()` function that can be used to skip evaluating initializers and that also reports an error. The downside is that it duplicates the error message from `CheckObjectEntity()`.
https://github.com/llvm/llvm-project/pull/171163
More information about the flang-commits
mailing list