[flang-commits] [flang] fa53d92 - [flang] Check for errors when analyzing array constructors (#173092)
via flang-commits
flang-commits at lists.llvm.org
Thu Jan 8 06:33:27 PST 2026
Author: Leandro Lupori
Date: 2026-01-08T11:33:21-03:00
New Revision: fa53d9285aea19e453eda7e38d26d16eaf0f7c36
URL: https://github.com/llvm/llvm-project/commit/fa53d9285aea19e453eda7e38d26d16eaf0f7c36
DIFF: https://github.com/llvm/llvm-project/commit/fa53d9285aea19e453eda7e38d26d16eaf0f7c36.diff
LOG: [flang] Check for errors when analyzing array constructors (#173092)
Errors in array constructor values result in the array having
less elements than it should, which can cause other errors that
will confuse the user. Avoid this by not returning an expression
on errors.
Fixes #127425
Added:
flang/test/Semantics/bug127425.f90
Modified:
flang/lib/Semantics/expression.cpp
Removed:
################################################################################
diff --git a/flang/lib/Semantics/expression.cpp b/flang/lib/Semantics/expression.cpp
index 402e88252fc20..fd0a16f19ccc4 100644
--- a/flang/lib/Semantics/expression.cpp
+++ b/flang/lib/Semantics/expression.cpp
@@ -2075,11 +2075,15 @@ MaybeExpr ArrayConstructorContext::ToExpr() {
MaybeExpr ExpressionAnalyzer::Analyze(const parser::ArrayConstructor &array) {
const parser::AcSpec &acSpec{array.v};
+ bool hadAnyFatalError{context_.AnyFatalError()};
ArrayConstructorContext acContext{
*this, AnalyzeTypeSpec(acSpec.type, GetFoldingContext())};
for (const parser::AcValue &value : acSpec.values) {
acContext.Add(value);
}
+ if (!hadAnyFatalError && context_.AnyFatalError()) {
+ return std::nullopt;
+ }
return acContext.ToExpr();
}
diff --git a/flang/test/Semantics/bug127425.f90 b/flang/test/Semantics/bug127425.f90
new file mode 100644
index 0000000000000..3cd3abd55a075
--- /dev/null
+++ b/flang/test/Semantics/bug127425.f90
@@ -0,0 +1,10 @@
+! RUN: %python %S/test_errors.py %s %flang_fc1
+
+program main
+ implicit none
+ integer :: ja, jb, j3, j4, j5
+ pointer (j1,ja)
+ pointer (j2,jb)
+ !ERROR: Values in array constructor must have the same declared type when no explicit type appears
+ if (any((/j1,j2,j3,j4,j5/)/=(/1,2,3,4,5/))) print *,'fail'
+end program main
More information about the flang-commits
mailing list