Skip to content

Commit 4a11ba7

Browse files
committed
[flang] Ensure names resolve in DATA statement objects
When DATA statement objects have derived types obtained by implicit typing rules, their types aren't known until specification part processing is complete. In the case of a derived type, any component name in a designator may still be in need of name resolution. Take care of it in the deferred check visitor that runs at the end of name resolution in each specification and execution part. Fixes #82069.
1 parent 2236048 commit 4a11ba7

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

flang/lib/Semantics/resolve-names.cpp

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8398,21 +8398,22 @@ bool ResolveNamesVisitor::Pre(const parser::PointerAssignmentStmt &x) {
83988398
Walk(expr);
83998399
return false;
84008400
}
8401+
84018402
void ResolveNamesVisitor::Post(const parser::Designator &x) {
84028403
ResolveDesignator(x);
84038404
}
84048405
void ResolveNamesVisitor::Post(const parser::SubstringInquiry &x) {
84058406
Walk(std::get<parser::SubstringRange>(x.v.t).t);
84068407
ResolveDataRef(std::get<parser::DataRef>(x.v.t));
84078408
}
8408-
84098409
void ResolveNamesVisitor::Post(const parser::ProcComponentRef &x) {
84108410
ResolveStructureComponent(x.v.thing);
84118411
}
84128412
void ResolveNamesVisitor::Post(const parser::TypeGuardStmt &x) {
84138413
DeclTypeSpecVisitor::Post(x);
84148414
ConstructVisitor::Post(x);
84158415
}
8416+
84168417
bool ResolveNamesVisitor::Pre(const parser::StmtFunctionStmt &x) {
84178418
if (HandleStmtFunction(x)) {
84188419
return false;
@@ -8950,6 +8951,8 @@ void ResolveNamesVisitor::EndScopeForNode(const ProgramTree &node) {
89508951
// pointers, are deferred until all of the pertinent specification parts
89518952
// have been visited. This deferred processing enables the use of forward
89528953
// references in these circumstances.
8954+
// Data statement objects with implicit derived types are finally
8955+
// resolved here.
89538956
class DeferredCheckVisitor {
89548957
public:
89558958
explicit DeferredCheckVisitor(ResolveNamesVisitor &resolver)
@@ -9010,6 +9013,16 @@ class DeferredCheckVisitor {
90109013
resolver_.CheckBindings(tbps);
90119014
}
90129015
}
9016+
bool Pre(const parser::DataStmtObject &) {
9017+
++dataStmtObjectNesting_;
9018+
return true;
9019+
}
9020+
void Post(const parser::DataStmtObject &) { --dataStmtObjectNesting_; }
9021+
void Post(const parser::Designator &x) {
9022+
if (dataStmtObjectNesting_ > 0) {
9023+
resolver_.ResolveDesignator(x);
9024+
}
9025+
}
90139026

90149027
private:
90159028
void Init(const parser::Name &name,
@@ -9032,6 +9045,7 @@ class DeferredCheckVisitor {
90329045

90339046
ResolveNamesVisitor &resolver_;
90349047
bool pushedScope_{false};
9048+
int dataStmtObjectNesting_{0};
90359049
};
90369050

90379051
// Perform checks and completions that need to happen after all of

flang/test/Semantics/data22.f90

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
! RUN: %flang_fc1 -fdebug-dump-symbols %s 2>&1 | FileCheck %s
2+
! Ensure that implicitly typed DATA statement objects with derived
3+
! types get their symbols resolved by the end of the name resolution pass.
4+
! CHECK: x1 (Implicit, InDataStmt) size=4 offset=0: ObjectEntity type: TYPE(t1) shape: 1_8:1_8 init:[t1::t1(n=123_4)]
5+
! CHECK: x2 (InDataStmt) size=4 offset=4: ObjectEntity type: TYPE(t2) shape: 1_8:1_8 init:[t2::t2(m=456_4)]
6+
implicit type(t1)(x)
7+
type t1
8+
integer n
9+
end type
10+
dimension x1(1), x2(1)
11+
data x1(1)%n /123/
12+
data x2(1)%m /456/
13+
type t2
14+
integer m
15+
end type
16+
type(t2) x2
17+
end

0 commit comments

Comments
 (0)