Skip to content

Commit 081e202

Browse files
authored
[flang] Fix DATA-like default component initialization (#82784)
Ensure that the values in a DATA-like default component initialization pass through expression analysis. Fixes #81097.
1 parent a56ef9f commit 081e202

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

flang/include/flang/Semantics/expression.h

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -506,9 +506,18 @@ class ExprChecker {
506506
}
507507

508508
bool Pre(const parser::ComponentDefStmt &) {
509-
// Already analyzed in name resolution and PDT instantiation;
510-
// do not attempt to re-analyze now without type parameters.
511-
return false;
509+
inComponentDefStmt_ = true;
510+
return true;
511+
}
512+
void Post(const parser::ComponentDefStmt &) { inComponentDefStmt_ = false; }
513+
bool Pre(const parser::Initialization &x) {
514+
// Default component initialization expressions (but not DATA-like ones
515+
// as in DEC STRUCTUREs) were already analyzed in name resolution
516+
// and PDT instantiation; do not attempt to re-analyze them without
517+
// type parameters.
518+
return !inComponentDefStmt_ ||
519+
std::holds_alternative<
520+
std::list<common::Indirection<parser::DataStmtValue>>>(x.u);
512521
}
513522

514523
template <typename A> bool Pre(const parser::Scalar<A> &x) {
@@ -538,6 +547,7 @@ class ExprChecker {
538547
SemanticsContext &context_;
539548
evaluate::ExpressionAnalyzer exprAnalyzer_{context_};
540549
int whereDepth_{0}; // nesting of WHERE statements & constructs
550+
bool inComponentDefStmt_{false};
541551
};
542552
} // namespace Fortran::semantics
543553
#endif // FORTRAN_SEMANTICS_EXPRESSION_H_

flang/test/Semantics/data21.f90

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
! RUN: %flang_fc1 -fdebug-dump-symbols %s 2>&1 | FileCheck %s
2+
! Ensure that DATA-like default component initializers work.
3+
! CHECK: j (InDataStmt) size=4 offset=0: ObjectEntity type: INTEGER(4) init:123_4
4+
type t
5+
integer j/123/
6+
end type
7+
end

0 commit comments

Comments
 (0)