forked from OSchip/llvm-project
[flang] Fix CheckSpecificationExpr handling of associated names
Avoid a spurious error message about a dummy procedure reference in a specification expression by restructuring the handling of use-associated and host-associated symbols. Updated to fix a circular dependence between shared library binaries that was introduced by the original patch. Differential revision: https://reviews.llvm.org/D91286
This commit is contained in:
parent
d9cbceb041
commit
67b13e9785
|
@ -84,8 +84,13 @@ public:
|
||||||
}
|
}
|
||||||
Kind kind() const { return kind_; }
|
Kind kind() const { return kind_; }
|
||||||
bool IsGlobal() const { return kind_ == Kind::Global; }
|
bool IsGlobal() const { return kind_ == Kind::Global; }
|
||||||
bool IsModule() const; // only module, not submodule
|
bool IsModule() const {
|
||||||
bool IsSubmodule() const;
|
return kind_ == Kind::Module &&
|
||||||
|
!symbol_->get<ModuleDetails>().isSubmodule();
|
||||||
|
}
|
||||||
|
bool IsSubmodule() const {
|
||||||
|
return kind_ == Kind::Module && symbol_->get<ModuleDetails>().isSubmodule();
|
||||||
|
}
|
||||||
bool IsDerivedType() const { return kind_ == Kind::DerivedType; }
|
bool IsDerivedType() const { return kind_ == Kind::DerivedType; }
|
||||||
bool IsStmtFunction() const;
|
bool IsStmtFunction() const;
|
||||||
bool IsParameterizedDerivedType() const;
|
bool IsParameterizedDerivedType() const;
|
||||||
|
|
|
@ -258,30 +258,29 @@ public:
|
||||||
Result operator()(const CoarrayRef &) const { return "coindexed reference"; }
|
Result operator()(const CoarrayRef &) const { return "coindexed reference"; }
|
||||||
|
|
||||||
Result operator()(const semantics::Symbol &symbol) const {
|
Result operator()(const semantics::Symbol &symbol) const {
|
||||||
if (semantics::IsNamedConstant(symbol)) {
|
const auto &ultimate{symbol.GetUltimate()};
|
||||||
|
if (semantics::IsNamedConstant(ultimate) || ultimate.owner().IsModule() ||
|
||||||
|
ultimate.owner().IsSubmodule()) {
|
||||||
return std::nullopt;
|
return std::nullopt;
|
||||||
} else if (scope_.IsDerivedType() && IsVariableName(symbol)) { // C750, C754
|
} else if (scope_.IsDerivedType() &&
|
||||||
|
IsVariableName(ultimate)) { // C750, C754
|
||||||
return "derived type component or type parameter value not allowed to "
|
return "derived type component or type parameter value not allowed to "
|
||||||
"reference variable '"s +
|
"reference variable '"s +
|
||||||
symbol.name().ToString() + "'";
|
ultimate.name().ToString() + "'";
|
||||||
} else if (IsDummy(symbol)) {
|
} else if (IsDummy(ultimate)) {
|
||||||
if (symbol.attrs().test(semantics::Attr::OPTIONAL)) {
|
if (ultimate.attrs().test(semantics::Attr::OPTIONAL)) {
|
||||||
return "reference to OPTIONAL dummy argument '"s +
|
return "reference to OPTIONAL dummy argument '"s +
|
||||||
symbol.name().ToString() + "'";
|
ultimate.name().ToString() + "'";
|
||||||
} else if (symbol.attrs().test(semantics::Attr::INTENT_OUT)) {
|
} else if (ultimate.attrs().test(semantics::Attr::INTENT_OUT)) {
|
||||||
return "reference to INTENT(OUT) dummy argument '"s +
|
return "reference to INTENT(OUT) dummy argument '"s +
|
||||||
symbol.name().ToString() + "'";
|
ultimate.name().ToString() + "'";
|
||||||
} else if (symbol.has<semantics::ObjectEntityDetails>()) {
|
} else if (ultimate.has<semantics::ObjectEntityDetails>()) {
|
||||||
return std::nullopt;
|
return std::nullopt;
|
||||||
} else {
|
} else {
|
||||||
return "dummy procedure argument";
|
return "dummy procedure argument";
|
||||||
}
|
}
|
||||||
} else if (symbol.has<semantics::UseDetails>() ||
|
|
||||||
symbol.has<semantics::HostAssocDetails>() ||
|
|
||||||
symbol.owner().kind() == semantics::Scope::Kind::Module) {
|
|
||||||
return std::nullopt;
|
|
||||||
} else if (const auto *object{
|
} else if (const auto *object{
|
||||||
symbol.detailsIf<semantics::ObjectEntityDetails>()}) {
|
ultimate.detailsIf<semantics::ObjectEntityDetails>()}) {
|
||||||
// TODO: what about EQUIVALENCE with data in COMMON?
|
// TODO: what about EQUIVALENCE with data in COMMON?
|
||||||
// TODO: does this work for blank COMMON?
|
// TODO: does this work for blank COMMON?
|
||||||
if (object->commonBlock()) {
|
if (object->commonBlock()) {
|
||||||
|
@ -290,11 +289,11 @@ public:
|
||||||
}
|
}
|
||||||
for (const semantics::Scope *s{&scope_}; !s->IsGlobal();) {
|
for (const semantics::Scope *s{&scope_}; !s->IsGlobal();) {
|
||||||
s = &s->parent();
|
s = &s->parent();
|
||||||
if (s == &symbol.owner()) {
|
if (s == &ultimate.owner()) {
|
||||||
return std::nullopt;
|
return std::nullopt;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return "reference to local entity '"s + symbol.name().ToString() + "'";
|
return "reference to local entity '"s + ultimate.name().ToString() + "'";
|
||||||
}
|
}
|
||||||
|
|
||||||
Result operator()(const Component &x) const {
|
Result operator()(const Component &x) const {
|
||||||
|
|
|
@ -49,13 +49,6 @@ std::string EquivalenceObject::AsFortran() const {
|
||||||
return ss.str();
|
return ss.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Scope::IsModule() const {
|
|
||||||
return kind_ == Kind::Module && !symbol_->get<ModuleDetails>().isSubmodule();
|
|
||||||
}
|
|
||||||
bool Scope::IsSubmodule() const {
|
|
||||||
return kind_ == Kind::Module && symbol_->get<ModuleDetails>().isSubmodule();
|
|
||||||
}
|
|
||||||
|
|
||||||
Scope &Scope::MakeScope(Kind kind, Symbol *symbol) {
|
Scope &Scope::MakeScope(Kind kind, Symbol *symbol) {
|
||||||
return children_.emplace_back(*this, kind, symbol);
|
return children_.emplace_back(*this, kind, symbol);
|
||||||
}
|
}
|
||||||
|
|
|
@ -173,3 +173,12 @@ subroutine s15()
|
||||||
real, dimension((param + 2)) :: realField
|
real, dimension((param + 2)) :: realField
|
||||||
end type dtype
|
end type dtype
|
||||||
end subroutine s15
|
end subroutine s15
|
||||||
|
|
||||||
|
! Regression test: don't get confused by host association
|
||||||
|
subroutine s16(n)
|
||||||
|
integer :: n
|
||||||
|
contains
|
||||||
|
subroutine inner(r)
|
||||||
|
real, dimension(n) :: r
|
||||||
|
end subroutine
|
||||||
|
end subroutine s16
|
||||||
|
|
Loading…
Reference in New Issue