Skip to content

[flang] Fix DATA-like default component initialization #82784

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions flang/include/flang/Semantics/expression.h
Original file line number Diff line number Diff line change
Expand Up @@ -506,9 +506,18 @@ class ExprChecker {
}

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

template <typename A> bool Pre(const parser::Scalar<A> &x) {
Expand Down Expand Up @@ -538,6 +547,7 @@ class ExprChecker {
SemanticsContext &context_;
evaluate::ExpressionAnalyzer exprAnalyzer_{context_};
int whereDepth_{0}; // nesting of WHERE statements & constructs
bool inComponentDefStmt_{false};
};
} // namespace Fortran::semantics
#endif // FORTRAN_SEMANTICS_EXPRESSION_H_
7 changes: 7 additions & 0 deletions flang/test/Semantics/data21.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
! RUN: %flang_fc1 -fdebug-dump-symbols %s 2>&1 | FileCheck %s
! Ensure that DATA-like default component initializers work.
! CHECK: j (InDataStmt) size=4 offset=0: ObjectEntity type: INTEGER(4) init:123_4
type t
integer j/123/
end type
end