[flang-commits] [flang] [flang] Fix crash with legacy DATA initializer for an invalid declaration (PR #221170)
Mattéo Rizza Murgier via flang-commits
flang-commits at lists.llvm.org
Fri Sep 4 01:48:36 PDT 2026
https://github.com/matteo-rm created https://github.com/llvm/llvm-project/pull/221170
For legacy DATA /initialization/, declarations weren't checked for errors before construction, resulting in an assert crash. This PR fixes this by adding a check.
Fixes #220846
>From e5665ec5e5257532726a566a859ca3363c3450e3 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Matt=C3=A9o=20Rizza=20Murgier?=
<matteo.rizza-murgier at sipearl.com>
Date: Thu, 3 Sep 2026 21:20:18 +0200
Subject: [PATCH] [flang] Fix crash with legacy DATA initializer for an invalid
declaration
---
flang/lib/Semantics/check-data.cpp | 2 +-
flang/test/Semantics/data27.f90 | 7 +++++++
2 files changed, 8 insertions(+), 1 deletion(-)
create mode 100644 flang/test/Semantics/data27.f90
diff --git a/flang/lib/Semantics/check-data.cpp b/flang/lib/Semantics/check-data.cpp
index e8b7ea2eda63e..921128ced5d61 100644
--- a/flang/lib/Semantics/check-data.cpp
+++ b/flang/lib/Semantics/check-data.cpp
@@ -265,7 +265,7 @@ void DataChecker::Leave(const parser::EntityDecl &decl) {
const auto *list{
std::get_if<std::list<common::Indirection<parser::DataStmtValue>>>(
&init->u)};
- if (name && list) {
+ if (name && list && !exprAnalyzer_.context().HasError(*name)) {
AccumulateDataInitializations(inits_, exprAnalyzer_, *name, *list);
}
}
diff --git a/flang/test/Semantics/data27.f90 b/flang/test/Semantics/data27.f90
new file mode 100644
index 0000000000000..4dd6230c0b957
--- /dev/null
+++ b/flang/test/Semantics/data27.f90
@@ -0,0 +1,7 @@
+! RUN: %python %S/test_errors.py %s %flang_fc1
+program main
+ type foo
+ end type foo
+ !ERROR: 'foo' is already declared in this scoping unit
+ integer foo(1) /2/
+end program main
More information about the flang-commits
mailing list