Skip to content

Commit 5e2788c

Browse files
committed
[flang] Fix spurious error messages due to INTRINSIC nested in BLOCK
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 fef4c8a commit 5e2788c

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
@@ -4787,10 +4787,13 @@ void DeclarationVisitor::Post(const parser::EntityDecl &x) {
47874787
} else if (attrs.test(Attr::PARAMETER)) { // C882, C883
47884788
Say(name, "Missing initialization for parameter '%s'"_err_en_US);
47894789
}
4790-
if (auto *scopeSymbol{currScope().symbol()})
4791-
if (auto *details{scopeSymbol->detailsIf<DerivedTypeDetails>()})
4792-
if (details->isDECStructure())
4790+
if (auto *scopeSymbol{currScope().symbol()}) {
4791+
if (auto *details{scopeSymbol->detailsIf<DerivedTypeDetails>()}) {
4792+
if (details->isDECStructure()) {
47934793
details->add_component(symbol);
4794+
}
4795+
}
4796+
}
47944797
}
47954798

47964799
void DeclarationVisitor::Post(const parser::PointerDecl &x) {
@@ -7660,10 +7663,54 @@ class ExecutionPartSkimmerBase {
76607663
--blockDepth_;
76617664
PopScope();
76627665
}
7666+
// Note declarations of local names in BLOCK constructs.
7667+
// Don't have to worry about INTENT(), VALUE, or OPTIONAL
7668+
// (pertinent only to dummy arguments), ASYNCHRONOUS/VOLATILE,
7669+
// or accessibility attributes,
76637670
bool Pre(const parser::EntityDecl &x) {
76647671
Hide(std::get<parser::ObjectName>(x.t));
76657672
return true;
76667673
}
7674+
bool Pre(const parser::ObjectDecl &x) {
7675+
Hide(std::get<parser::ObjectName>(x.t));
7676+
return true;
7677+
}
7678+
bool Pre(const parser::PointerDecl &x) {
7679+
Hide(std::get<parser::Name>(x.t));
7680+
return true;
7681+
}
7682+
bool Pre(const parser::BindEntity &x) {
7683+
Hide(std::get<parser::Name>(x.t));
7684+
return true;
7685+
}
7686+
bool Pre(const parser::ContiguousStmt &x) {
7687+
for (const parser::Name &name : x.v) {
7688+
Hide(name);
7689+
}
7690+
return true;
7691+
}
7692+
bool Pre(const parser::DimensionStmt::Declaration &x) {
7693+
Hide(std::get<parser::Name>(x.t));
7694+
return true;
7695+
}
7696+
bool Pre(const parser::ExternalStmt &x) {
7697+
for (const parser::Name &name : x.v) {
7698+
Hide(name);
7699+
}
7700+
return true;
7701+
}
7702+
bool Pre(const parser::IntrinsicStmt &x) {
7703+
for (const parser::Name &name : x.v) {
7704+
Hide(name);
7705+
}
7706+
return true;
7707+
}
7708+
bool Pre(const parser::CodimensionStmt &x) {
7709+
for (const parser::CodimensionDecl &decl : x.v) {
7710+
Hide(std::get<parser::Name>(decl.t));
7711+
}
7712+
return true;
7713+
}
76677714
void Post(const parser::ImportStmt &x) {
76687715
if (x.kind == common::ImportKind::None ||
76697716
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)