[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:08:33 PDT 2026


llvmorg-github-actions[bot] wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-flang-semantics

Author: ejose02

<details>
<summary>Changes</summary>

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.

---
Full diff: https://github.com/llvm/llvm-project/pull/213598.diff


2 Files Affected:

- (modified) flang/lib/Semantics/check-data.cpp (+6) 
- (added) flang/test/Semantics/data-pdt.f90 (+12) 


``````````diff
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

``````````

</details>


https://github.com/llvm/llvm-project/pull/213598


More information about the flang-commits mailing list