[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
Fri Dec 12 06:35:50 PST 2025


================
@@ -10622,11 +10641,13 @@ class DeferredCheckVisitor {
 private:
   void Init(const parser::Name &name,
       const std::optional<parser::Initialization> &init) {
-    if (init) {
+    // Don't evaluate initializers for arrays with a rank greater than the
+    // maximum supported, to avoid running out of memory.
+    if (init && name.symbol && resolver_.CheckRank(*name.symbol)) {
       if (const auto *target{
               std::get_if<parser::InitialDataTarget>(&init->u)}) {
         resolver_.PointerInitialization(name, *target);
-      } else if (name.symbol) {
----------------
luporl wrote:

I don't follow why, since this check was moved to the enclosing `if`:

```c++
    if (init && name.symbol && resolver_.CheckRank(*name.symbol)) {
```

The only difference I see is that now `PointerInitialization()` is not called when `name.symbol` is false, but it didn't do anything in this case, so the behavior is the same.

Am I missing something?

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


More information about the flang-commits mailing list