Skip to content

Commit c7a4163

Browse files
authored
[flang] Handle DATA-style default component /inits/ in time (#159469)
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.)
1 parent fd81bd8 commit c7a4163

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

flang/lib/Semantics/data-to-inits.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -943,10 +943,19 @@ void ConstructInitializer(const Symbol &symbol,
943943

944944
void ConvertToInitializers(
945945
DataInitializations &inits, evaluate::ExpressionAnalyzer &exprAnalyzer) {
946+
// Process DATA-style component /initializers/ now, so that they appear as
947+
// default values in time for EQUIVALENCE processing in ProcessScopes.
948+
for (auto &[symbolPtr, initialization] : inits) {
949+
if (symbolPtr->owner().IsDerivedType()) {
950+
ConstructInitializer(*symbolPtr, initialization, exprAnalyzer);
951+
}
952+
}
946953
if (ProcessScopes(
947954
exprAnalyzer.context().globalScope(), exprAnalyzer, inits)) {
948955
for (auto &[symbolPtr, initialization] : inits) {
949-
ConstructInitializer(*symbolPtr, initialization, exprAnalyzer);
956+
if (!symbolPtr->owner().IsDerivedType()) {
957+
ConstructInitializer(*symbolPtr, initialization, exprAnalyzer);
958+
}
950959
}
951960
}
952961
}

flang/test/Semantics/data24.f90

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
! RUN: %flang_fc1 -fdebug-dump-symbols %s 2>&1 | FileCheck %s
2+
! Ensure that DATA-style default component /initializers/ are processed
3+
! before they are needed to handle EQUIVALENCE'd storage.
4+
type t
5+
sequence
6+
integer :: j(10) /1,2,3,4,5,6,7,8,9,10/
7+
end type
8+
type(t) :: A
9+
integer arr(10)
10+
equivalence (A, arr)
11+
end
12+
13+
!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]
14+
!CHECK: a size=40 offset=0: ObjectEntity type: TYPE(t)
15+
!CHECK: arr size=40 offset=0: ObjectEntity type: INTEGER(4) shape: 1_8:10_8
16+
!CHECK: Equivalence Sets: (a,arr(1)) (.F18.0,a)

0 commit comments

Comments
 (0)