[flang-commits] [flang] [flang] Don't evaluate initializers for arrays with invalid rank (PR #171163)

via flang-commits flang-commits at lists.llvm.org
Mon Dec 8 09:47:21 PST 2025


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-flang-semantics

Author: Leandro Lupori (luporl)

<details>
<summary>Changes</summary>

Evaluating initializers for arrays with a rank greater than the
maximum supported can make the compiler run out of memory.

Fixes #<!-- -->124488


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


1 Files Affected:

- (modified) flang/lib/Semantics/resolve-names.cpp (+5) 


``````````diff
diff --git a/flang/lib/Semantics/resolve-names.cpp b/flang/lib/Semantics/resolve-names.cpp
index 345a0e4e8ecce..c070546c6729d 100644
--- a/flang/lib/Semantics/resolve-names.cpp
+++ b/flang/lib/Semantics/resolve-names.cpp
@@ -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
+  // maximum supported, to avoid running out of memory.
+  if (name.symbol && name.symbol->Rank() > common::maxRank) {
+    return;
+  }
   if (CheckNonPointerInitialization(
           name, /*inLegacyDataInitialization=*/false)) {
     Symbol &ultimate{name.symbol->GetUltimate()};

``````````

</details>


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


More information about the flang-commits mailing list