Skip to content

Commit f50f0ca

Browse files
authored
[flang] Fix crash in name resolution (#85835)
ConvertToObjectEntity() returns true for use- and host-associated object symbols, too. Ensure in this case that the symbol really is a non-associated object. Fixes #85776.
1 parent 6d579cd commit f50f0ca

File tree

2 files changed

+18
-9
lines changed

2 files changed

+18
-9
lines changed

flang/lib/Semantics/resolve-names.cpp

+9-9
Original file line numberDiff line numberDiff line change
@@ -4646,23 +4646,23 @@ bool DeclarationVisitor::Pre(const parser::OldParameterStmt &x) {
46464646
bool DeclarationVisitor::Pre(const parser::NamedConstantDef &x) {
46474647
auto &name{std::get<parser::NamedConstant>(x.t).v};
46484648
auto &symbol{HandleAttributeStmt(Attr::PARAMETER, name)};
4649-
if (!ConvertToObjectEntity(symbol) ||
4650-
symbol.test(Symbol::Flag::CrayPointer) ||
4649+
ConvertToObjectEntity(symbol);
4650+
auto *details{symbol.detailsIf<ObjectEntityDetails>()};
4651+
if (!details || symbol.test(Symbol::Flag::CrayPointer) ||
46514652
symbol.test(Symbol::Flag::CrayPointee)) {
46524653
SayWithDecl(
46534654
name, symbol, "PARAMETER attribute not allowed on '%s'"_err_en_US);
46544655
return false;
46554656
}
46564657
const auto &expr{std::get<parser::ConstantExpr>(x.t)};
4657-
auto &details{symbol.get<ObjectEntityDetails>()};
4658-
if (details.init() || symbol.test(Symbol::Flag::InDataStmt)) {
4658+
if (details->init() || symbol.test(Symbol::Flag::InDataStmt)) {
46594659
Say(name, "Named constant '%s' already has a value"_err_en_US);
46604660
}
46614661
if (inOldStyleParameterStmt_) {
46624662
// non-standard extension PARAMETER statement (no parentheses)
46634663
Walk(expr);
46644664
auto folded{EvaluateExpr(expr)};
4665-
if (details.type()) {
4665+
if (details->type()) {
46664666
SayWithDecl(name, symbol,
46674667
"Alternative style PARAMETER '%s' must not already have an explicit type"_err_en_US);
46684668
} else if (folded) {
@@ -4674,9 +4674,9 @@ bool DeclarationVisitor::Pre(const parser::NamedConstantDef &x) {
46744674
} else if (auto shape{ToArraySpec(
46754675
GetFoldingContext(), evaluate::GetShape(*folded))}) {
46764676
// The type of the named constant is assumed from the expression.
4677-
details.set_type(*type);
4678-
details.set_init(std::move(*folded));
4679-
details.set_shape(std::move(*shape));
4677+
details->set_type(*type);
4678+
details->set_init(std::move(*folded));
4679+
details->set_shape(std::move(*shape));
46804680
} else {
46814681
Say(at, "The expression must have constant shape"_err_en_US);
46824682
}
@@ -4693,7 +4693,7 @@ bool DeclarationVisitor::Pre(const parser::NamedConstantDef &x) {
46934693
Walk(expr);
46944694
if (auto converted{EvaluateNonPointerInitializer(
46954695
symbol, expr, expr.thing.value().source)}) {
4696-
details.set_init(std::move(*converted));
4696+
details->set_init(std::move(*converted));
46974697
}
46984698
}
46994699
return false;

flang/test/Semantics/resolve61.f90

+9
Original file line numberDiff line numberDiff line change
@@ -126,3 +126,12 @@ subroutine s
126126
pointer(ip, x) ! ok, local declaration
127127
end
128128
end
129+
130+
subroutine p14
131+
real :: r
132+
block
133+
asynchronous :: r
134+
!ERROR: PARAMETER attribute not allowed on 'r'
135+
parameter (r = 1.0)
136+
end block
137+
end

0 commit comments

Comments
 (0)