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

Peter Klausler via flang-commits flang-commits at lists.llvm.org
Wed Feb 25 09:09:26 PST 2026


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

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

>From ae17ca9cc18b1c26edca1f677c7391a2a8ad759b Mon Sep 17 00:00:00 2001
From: Peter Klausler <pklausler at nvidia.com>
Date: Wed, 25 Feb 2026 09:04:53 -0800
Subject: [PATCH] [flang] Fix crash on error case

A named constant implicit-shape array with a non-constant lower bound
is an error case.  Emit an error message rather than crashing.
---
 flang/lib/Evaluate/check-expression.cpp | 13 +++++++++----
 flang/test/Semantics/bug2292.f90        |  5 +++++
 2 files changed, 14 insertions(+), 4 deletions(-)
 create mode 100644 flang/test/Semantics/bug2292.f90

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



More information about the flang-commits mailing list