[flang-commits] [flang] [Flang] Handle spurious DATA error for PDT character components (PR #213598)
via flang-commits
flang-commits at lists.llvm.org
Sun Aug 2 23:07:54 PDT 2026
https://github.com/ejose02 created https://github.com/llvm/llvm-project/pull/213598
Fixes #193188
IsAutomatic treats PDT character components with length type parameters as automatic because length is not folded to a constant in instantiation scope.
Emit a not-yet-implemented diagnostic for DATA initialization of components in parameterized derived type instances instead of the spurious automatic-variable error.
>From 288e8b1203586152fddce08079fc48fce4d554f2 Mon Sep 17 00:00:00 2001
From: ejose <ejose at amd.com>
Date: Mon, 3 Aug 2026 06:03:20 +0000
Subject: [PATCH] [Flang] Handle spurious DATA error for PDT character
components
IsAutomatic treats PDT character components with length type parameters as automatic because length is not folded to a constant in instantiation scope.
Emit a not-yet-implemented diagnostic for DATA initialization of components in parameterized derived type instances instead of the spurious automatic-variable error.
---
flang/lib/Semantics/check-data.cpp | 6 ++++++
flang/test/Semantics/data-pdt.f90 | 12 ++++++++++++
2 files changed, 18 insertions(+)
create mode 100644 flang/test/Semantics/data-pdt.f90
diff --git a/flang/lib/Semantics/check-data.cpp b/flang/lib/Semantics/check-data.cpp
index e8b7ea2eda63e..4e79a0ed15515 100644
--- a/flang/lib/Semantics/check-data.cpp
+++ b/flang/lib/Semantics/check-data.cpp
@@ -58,6 +58,12 @@ class DataVarChecker : public evaluate::AllTraverse<DataVarChecker, true> {
const Scope &scope{context_.FindScope(source_)};
bool isFirstSymbol{isFirstSymbol_};
isFirstSymbol_ = false;
+ if (IsAutomatic(symbol) &&
+ symbol.owner().IsParameterizedDerivedTypeInstantiation()) {
+ context_.Say(source_,
+ "DATA statement initialization of a component in a parameterized derived type instance"_todo_en_US);
+ return false;
+ }
// Ordered so that most egregious errors are first
if (const char *whyNot{IsProcedure(symbol) && !IsPointer(symbol)
? "Procedure"
diff --git a/flang/test/Semantics/data-pdt.f90 b/flang/test/Semantics/data-pdt.f90
new file mode 100644
index 0000000000000..cfa2507660c1a
--- /dev/null
+++ b/flang/test/Semantics/data-pdt.f90
@@ -0,0 +1,12 @@
+! RUN: %python %S/test_errors.py %s %flang_fc1
+! DATA on components of a parameterized derived type instance is not yet
+! supported.
+program test
+ type ut(n)
+ integer, len :: n
+ character(n) :: sar(2)
+ end type
+ type(ut(1)) pdt
+ !ERROR: not yet implemented: DATA statement initialization of a component in a parameterized derived type instance
+ data pdt%sar/'o','k'/
+end program
More information about the flang-commits
mailing list