Skip to content

[flang] Fix crash in name resolution #85835

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions flang/lib/Semantics/resolve-names.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4646,23 +4646,23 @@ bool DeclarationVisitor::Pre(const parser::OldParameterStmt &x) {
bool DeclarationVisitor::Pre(const parser::NamedConstantDef &x) {
auto &name{std::get<parser::NamedConstant>(x.t).v};
auto &symbol{HandleAttributeStmt(Attr::PARAMETER, name)};
if (!ConvertToObjectEntity(symbol) ||
symbol.test(Symbol::Flag::CrayPointer) ||
ConvertToObjectEntity(symbol);
auto *details{symbol.detailsIf<ObjectEntityDetails>()};
if (!details || symbol.test(Symbol::Flag::CrayPointer) ||
symbol.test(Symbol::Flag::CrayPointee)) {
SayWithDecl(
name, symbol, "PARAMETER attribute not allowed on '%s'"_err_en_US);
return false;
}
const auto &expr{std::get<parser::ConstantExpr>(x.t)};
auto &details{symbol.get<ObjectEntityDetails>()};
if (details.init() || symbol.test(Symbol::Flag::InDataStmt)) {
if (details->init() || symbol.test(Symbol::Flag::InDataStmt)) {
Say(name, "Named constant '%s' already has a value"_err_en_US);
}
if (inOldStyleParameterStmt_) {
// non-standard extension PARAMETER statement (no parentheses)
Walk(expr);
auto folded{EvaluateExpr(expr)};
if (details.type()) {
if (details->type()) {
SayWithDecl(name, symbol,
"Alternative style PARAMETER '%s' must not already have an explicit type"_err_en_US);
} else if (folded) {
Expand All @@ -4674,9 +4674,9 @@ bool DeclarationVisitor::Pre(const parser::NamedConstantDef &x) {
} else if (auto shape{ToArraySpec(
GetFoldingContext(), evaluate::GetShape(*folded))}) {
// The type of the named constant is assumed from the expression.
details.set_type(*type);
details.set_init(std::move(*folded));
details.set_shape(std::move(*shape));
details->set_type(*type);
details->set_init(std::move(*folded));
details->set_shape(std::move(*shape));
} else {
Say(at, "The expression must have constant shape"_err_en_US);
}
Expand All @@ -4693,7 +4693,7 @@ bool DeclarationVisitor::Pre(const parser::NamedConstantDef &x) {
Walk(expr);
if (auto converted{EvaluateNonPointerInitializer(
symbol, expr, expr.thing.value().source)}) {
details.set_init(std::move(*converted));
details->set_init(std::move(*converted));
}
}
return false;
Expand Down
9 changes: 9 additions & 0 deletions flang/test/Semantics/resolve61.f90
Original file line number Diff line number Diff line change
Expand Up @@ -126,3 +126,12 @@ subroutine s
pointer(ip, x) ! ok, local declaration
end
end

subroutine p14
real :: r
block
asynchronous :: r
!ERROR: PARAMETER attribute not allowed on 'r'
parameter (r = 1.0)
end block
end