Skip to content

[flang] Ensure names resolve in DATA statement objects #82825

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 2, 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
28 changes: 21 additions & 7 deletions flang/lib/Semantics/resolve-names.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8950,6 +8950,8 @@ void ResolveNamesVisitor::EndScopeForNode(const ProgramTree &node) {
// pointers, are deferred until all of the pertinent specification parts
// have been visited. This deferred processing enables the use of forward
// references in these circumstances.
// Data statement objects with implicit derived types are finally
// resolved here.
class DeferredCheckVisitor {
public:
explicit DeferredCheckVisitor(ResolveNamesVisitor &resolver)
Expand All @@ -8965,16 +8967,17 @@ class DeferredCheckVisitor {
if (Symbol * symbol{name.symbol}) {
if (Scope * scope{symbol->scope()}) {
if (scope->IsDerivedType()) {
resolver_.PushScope(*scope);
pushedScope_ = true;
CHECK(outerScope_ == nullptr);
outerScope_ = &resolver_.currScope();
resolver_.SetScope(*scope);
}
}
}
}
void Post(const parser::EndTypeStmt &) {
if (pushedScope_) {
resolver_.PopScope();
pushedScope_ = false;
if (outerScope_) {
resolver_.SetScope(*outerScope_);
outerScope_ = nullptr;
}
}

Expand Down Expand Up @@ -9006,10 +9009,20 @@ class DeferredCheckVisitor {
resolver_.CheckExplicitInterface(tbps.interfaceName);
}
void Post(const parser::TypeBoundProcedureStmt::WithoutInterface &tbps) {
if (pushedScope_) {
if (outerScope_) {
resolver_.CheckBindings(tbps);
}
}
bool Pre(const parser::DataStmtObject &) {
++dataStmtObjectNesting_;
return true;
}
void Post(const parser::DataStmtObject &) { --dataStmtObjectNesting_; }
void Post(const parser::Designator &x) {
if (dataStmtObjectNesting_ > 0) {
resolver_.ResolveDesignator(x);
}
}

private:
void Init(const parser::Name &name,
Expand All @@ -9031,7 +9044,8 @@ class DeferredCheckVisitor {
}

ResolveNamesVisitor &resolver_;
bool pushedScope_{false};
Scope *outerScope_{nullptr};
int dataStmtObjectNesting_{0};
};

// Perform checks and completions that need to happen after all of
Expand Down
17 changes: 17 additions & 0 deletions flang/test/Semantics/data22.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
! RUN: %flang_fc1 -fdebug-dump-symbols %s 2>&1 | FileCheck %s
! Ensure that implicitly typed DATA statement objects with derived
! types get their symbols resolved by the end of the name resolution pass.
! CHECK: x1 (Implicit, InDataStmt) size=4 offset=0: ObjectEntity type: TYPE(t1) shape: 1_8:1_8 init:[t1::t1(n=123_4)]
! CHECK: x2 (InDataStmt) size=4 offset=4: ObjectEntity type: TYPE(t2) shape: 1_8:1_8 init:[t2::t2(m=456_4)]
implicit type(t1)(x)
type t1
integer n
end type
dimension x1(1), x2(1)
data x1(1)%n /123/
data x2(1)%m /456/
type t2
integer m
end type
type(t2) x2
end