Skip to content

Conversation

klausler
Copy link
Contributor

DEC-style default component initializers that use DATA statement syntax aren't processed until DATA statement values are converted into init() expressions in the symbol table. Part of that conversion process involves combining storage-associated (EQUIVALENCE) symbols with compiler-generated symbols with initialization when the associated symbols have initialization, and part of that process involves the application of default component initializers; so we need to make sure that they've already been processed.

(Fixes Fujitsu Fortran test 0633_0004.f.)

DEC-style default component initializers that use DATA statement
syntax aren't processed until DATA statement values are converted
into init() expressions in the symbol table.  Part of that conversion
process involves combining storage-associated (EQUIVALENCE) symbols
with compiler-generated symbols with initialization when the
associated symbols have initialization, and part of that process
involves the application of default component initializers; so
we need to make sure that they've already been processed.

(Fixes Fujitsu Fortran test 0633_0004.f.)
@llvmbot llvmbot added flang Flang issues not falling into any other category flang:semantics labels Sep 17, 2025
@llvmbot
Copy link
Member

llvmbot commented Sep 17, 2025

@llvm/pr-subscribers-flang-semantics

Author: Peter Klausler (klausler)

Changes

DEC-style default component initializers that use DATA statement syntax aren't processed until DATA statement values are converted into init() expressions in the symbol table. Part of that conversion process involves combining storage-associated (EQUIVALENCE) symbols with compiler-generated symbols with initialization when the associated symbols have initialization, and part of that process involves the application of default component initializers; so we need to make sure that they've already been processed.

(Fixes Fujitsu Fortran test 0633_0004.f.)


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

2 Files Affected:

  • (modified) flang/lib/Semantics/data-to-inits.cpp (+10-1)
  • (added) flang/test/Semantics/data24.f90 (+16)
diff --git a/flang/lib/Semantics/data-to-inits.cpp b/flang/lib/Semantics/data-to-inits.cpp
index 1c454385e6989..1e46dabe30c89 100644
--- a/flang/lib/Semantics/data-to-inits.cpp
+++ b/flang/lib/Semantics/data-to-inits.cpp
@@ -943,10 +943,19 @@ void ConstructInitializer(const Symbol &symbol,
 
 void ConvertToInitializers(
     DataInitializations &inits, evaluate::ExpressionAnalyzer &exprAnalyzer) {
+  // Process DATA-style component /initializers/ now, so that they appear as
+  // default values in time for EQUIVALENCE processing in ProcessScopes.
+  for (auto &[symbolPtr, initialization] : inits) {
+    if (symbolPtr->owner().IsDerivedType()) {
+      ConstructInitializer(*symbolPtr, initialization, exprAnalyzer);
+    }
+  }
   if (ProcessScopes(
           exprAnalyzer.context().globalScope(), exprAnalyzer, inits)) {
     for (auto &[symbolPtr, initialization] : inits) {
-      ConstructInitializer(*symbolPtr, initialization, exprAnalyzer);
+      if (!symbolPtr->owner().IsDerivedType()) {
+        ConstructInitializer(*symbolPtr, initialization, exprAnalyzer);
+      }
     }
   }
 }
diff --git a/flang/test/Semantics/data24.f90 b/flang/test/Semantics/data24.f90
new file mode 100644
index 0000000000000..b645bd1ff5bc6
--- /dev/null
+++ b/flang/test/Semantics/data24.f90
@@ -0,0 +1,16 @@
+! RUN: %flang_fc1 -fdebug-dump-symbols %s 2>&1 | FileCheck %s
+! Ensure that DATA-style default component /initializers/ are processed
+! before they are needed to handle EQUIVALENCE'd storage.
+type t
+  sequence
+  integer :: j(10) /1,2,3,4,5,6,7,8,9,10/
+end type
+type(t) :: A
+integer arr(10)
+equivalence (A, arr)
+end
+
+!CHECK: .F18.0, SAVE (CompilerCreated) size=40 offset=0: ObjectEntity type: INTEGER(4) shape: 1_8:10_8 init:[INTEGER(4)::1_4,2_4,3_4,4_4,5_4,6_4,7_4,8_4,9_4,10_4]
+!CHECK: a size=40 offset=0: ObjectEntity type: TYPE(t)
+!CHECK: arr size=40 offset=0: ObjectEntity type: INTEGER(4) shape: 1_8:10_8
+!CHECK: Equivalence Sets: (a,arr(1)) (.F18.0,a)

@klausler klausler merged commit c7a4163 into llvm:main Sep 23, 2025
12 checks passed
@klausler klausler deleted the fj0633-0004 branch September 23, 2025 22:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

flang:semantics flang Flang issues not falling into any other category

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants