[flang-commits] [flang] [flang] Fix crash on error case (PR #183338)

via flang-commits flang-commits at lists.llvm.org
Wed Feb 25 09:10:21 PST 2026


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-flang-semantics

Author: Peter Klausler (klausler)

<details>
<summary>Changes</summary>

A named constant implicit-shape array with a non-constant lower bound is an error case.  Emit an error message rather than crashing.

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


2 Files Affected:

- (modified) flang/lib/Evaluate/check-expression.cpp (+9-4) 
- (added) flang/test/Semantics/bug2292.f90 (+5) 


``````````diff
diff --git a/flang/lib/Evaluate/check-expression.cpp b/flang/lib/Evaluate/check-expression.cpp
index f18953c1b9849..e73a4d82951af 100644
--- a/flang/lib/Evaluate/check-expression.cpp
+++ b/flang/lib/Evaluate/check-expression.cpp
@@ -563,10 +563,15 @@ std::optional<Expr<SomeType>> NonPointerInitializationExpr(const Symbol &symbol,
         int symRank{symTS->Rank()};
         if (IsImpliedShape(symbol)) {
           if (folded.Rank() == symRank) {
-            return ArrayConstantBoundChanger{
-                std::move(*AsConstantExtents(
-                    context, GetRawLowerBounds(context, NamedEntity{symbol})))}
-                .ChangeLbounds(std::move(folded));
+            if (auto lbounds{AsConstantExtents(context,
+                    GetRawLowerBounds(context, NamedEntity{symbol}))}) {
+              return ArrayConstantBoundChanger{std::move(*lbounds)}
+                  .ChangeLbounds(std::move(folded));
+            } else {
+              context.messages().Say(symbol.name(),
+                  "The lower bounds of the parameter '%s' are not constant"_err_en_US,
+                  symbol.name());
+            }
           } else {
             context.messages().Say(
                 "Implied-shape parameter '%s' has rank %d but its initializer has rank %d"_err_en_US,
diff --git a/flang/test/Semantics/bug2292.f90 b/flang/test/Semantics/bug2292.f90
new file mode 100644
index 0000000000000..87c1ff39390cf
--- /dev/null
+++ b/flang/test/Semantics/bug2292.f90
@@ -0,0 +1,5 @@
+!RUN: %python %S/test_errors.py %s %flang_fc1
+subroutine sub(lb)
+  !ERROR: The lower bounds of the parameter 'const' are not constant
+  integer, parameter :: const(lb:*) = [0]
+end

``````````

</details>


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


More information about the flang-commits mailing list