Skip to content

Commit d68332d

Browse files
authored
[flang] Fix spurious error messages due to INTRINSIC nested in BLOCK (#115889)
When skimmming executable parts to collect names used in procedure calls, it is important to exclude names that have local declarations in nested BLOCK constructs. The mechanism for handling these nested declarations was catching only names whose declarations include an "entity-decl", and so names appearing in other declaration statements (like INTRINSIC and EXTERNAL statements) were not hidden from the scan, leading to absurd error messages when such names turn out to be procedures in the nested BLOCK construct but to not be procedures outside it. This patch fixes the code that detects local declarations in BLOCK for all of the missed cases that don't use entity-decls; only INTRINSIC and EXTERNAL could affect the procedures whose names are of interest to the executable part skimmer, but perhaps future work will want to collect non-procedures as well, so I plugged all of the holes that I could find. Fixes #115674.
1 parent ebc0163 commit d68332d

File tree

2 files changed

+59
-3
lines changed

2 files changed

+59
-3
lines changed

flang/lib/Semantics/resolve-names.cpp

Lines changed: 50 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4821,10 +4821,13 @@ void DeclarationVisitor::Post(const parser::EntityDecl &x) {
48214821
} else if (attrs.test(Attr::PARAMETER)) { // C882, C883
48224822
Say(name, "Missing initialization for parameter '%s'"_err_en_US);
48234823
}
4824-
if (auto *scopeSymbol{currScope().symbol()})
4825-
if (auto *details{scopeSymbol->detailsIf<DerivedTypeDetails>()})
4826-
if (details->isDECStructure())
4824+
if (auto *scopeSymbol{currScope().symbol()}) {
4825+
if (auto *details{scopeSymbol->detailsIf<DerivedTypeDetails>()}) {
4826+
if (details->isDECStructure()) {
48274827
details->add_component(symbol);
4828+
}
4829+
}
4830+
}
48284831
}
48294832

48304833
void DeclarationVisitor::Post(const parser::PointerDecl &x) {
@@ -7694,10 +7697,54 @@ class ExecutionPartSkimmerBase {
76947697
--blockDepth_;
76957698
PopScope();
76967699
}
7700+
// Note declarations of local names in BLOCK constructs.
7701+
// Don't have to worry about INTENT(), VALUE, or OPTIONAL
7702+
// (pertinent only to dummy arguments), ASYNCHRONOUS/VOLATILE,
7703+
// or accessibility attributes,
76977704
bool Pre(const parser::EntityDecl &x) {
76987705
Hide(std::get<parser::ObjectName>(x.t));
76997706
return true;
77007707
}
7708+
bool Pre(const parser::ObjectDecl &x) {
7709+
Hide(std::get<parser::ObjectName>(x.t));
7710+
return true;
7711+
}
7712+
bool Pre(const parser::PointerDecl &x) {
7713+
Hide(std::get<parser::Name>(x.t));
7714+
return true;
7715+
}
7716+
bool Pre(const parser::BindEntity &x) {
7717+
Hide(std::get<parser::Name>(x.t));
7718+
return true;
7719+
}
7720+
bool Pre(const parser::ContiguousStmt &x) {
7721+
for (const parser::Name &name : x.v) {
7722+
Hide(name);
7723+
}
7724+
return true;
7725+
}
7726+
bool Pre(const parser::DimensionStmt::Declaration &x) {
7727+
Hide(std::get<parser::Name>(x.t));
7728+
return true;
7729+
}
7730+
bool Pre(const parser::ExternalStmt &x) {
7731+
for (const parser::Name &name : x.v) {
7732+
Hide(name);
7733+
}
7734+
return true;
7735+
}
7736+
bool Pre(const parser::IntrinsicStmt &x) {
7737+
for (const parser::Name &name : x.v) {
7738+
Hide(name);
7739+
}
7740+
return true;
7741+
}
7742+
bool Pre(const parser::CodimensionStmt &x) {
7743+
for (const parser::CodimensionDecl &decl : x.v) {
7744+
Hide(std::get<parser::Name>(decl.t));
7745+
}
7746+
return true;
7747+
}
77017748
void Post(const parser::ImportStmt &x) {
77027749
if (x.kind == common::ImportKind::None ||
77037750
x.kind == common::ImportKind::Only) {

flang/test/Semantics/bug115674.f90

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
!RUN: %flang_fc1 -fsyntax-only %s 2>&1 | FileCheck --allow-empty %s
2+
!CHECK-NOT: error:
3+
program main
4+
sin = 1
5+
block
6+
intrinsic sin
7+
print *, sin(0.)
8+
end block
9+
end

0 commit comments

Comments
 (0)