From 3550b66483fb17699b84b3b5437dccd83a325a2c Mon Sep 17 00:00:00 2001 From: Peter Klausler Date: Wed, 17 Sep 2025 15:33:07 -0700 Subject: [PATCH] [flang] Handle DATA-style default component /inits/ in time 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.) --- flang/lib/Semantics/data-to-inits.cpp | 11 ++++++++++- flang/test/Semantics/data24.f90 | 16 ++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 flang/test/Semantics/data24.f90 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)