Skip to content

[flang] Fix crash in error recovery #140768

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
6 changes: 5 additions & 1 deletion flang/lib/Semantics/expression.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3376,6 +3376,10 @@ MaybeExpr ExpressionAnalyzer::Analyze(const parser::FunctionReference &funcRef,
auto &mutableRef{const_cast<parser::FunctionReference &>(funcRef)};
*structureConstructor =
mutableRef.ConvertToStructureConstructor(type.derivedTypeSpec());
// Don't use saved typed expressions left over from argument
// analysis; they might not be valid structure components
// (e.g., a TYPE(*) argument)
auto restorer{DoNotUseSavedTypedExprs()};
return Analyze(structureConstructor->value());
}
}
Expand Down Expand Up @@ -4058,7 +4062,7 @@ MaybeExpr ExpressionAnalyzer::ExprOrVariable(
// first to be sure.
std::optional<parser::StructureConstructor> ctor;
result = Analyze(funcRef->value(), &ctor);
if (result && ctor) {
if (ctor) {
// A misparsed function reference is really a structure
// constructor. Repair the parse tree in situ.
const_cast<PARSED &>(x).u = std::move(*ctor);
Expand Down
10 changes: 10 additions & 0 deletions flang/test/Semantics/bug869.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
! RUN: %python %S/test_errors.py %s %flang_fc1
! Regression test for crash
subroutine sub(xx)
type(*) :: xx
type ty
end type
type(ty) obj
!ERROR: TYPE(*) dummy argument may only be used as an actual argument
obj = ty(xx)
end