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

via flang-commits flang-commits at lists.llvm.org
Thu Feb 26 07:11:25 PST 2026


Author: Peter Klausler
Date: 2026-02-26T07:11:20-08:00
New Revision: 8bae572c62407c6678699594953e4bd8ab218474

URL: https://github.com/llvm/llvm-project/commit/8bae572c62407c6678699594953e4bd8ab218474
DIFF: https://github.com/llvm/llvm-project/commit/8bae572c62407c6678699594953e4bd8ab218474.diff

LOG: [flang] Fix crash on error case (#183338)

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

Added: 
    flang/test/Semantics/bug2292.f90

Modified: 
    flang/lib/Evaluate/check-expression.cpp

Removed: 
    


################################################################################
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