[flang] Fix crash in error recovery (#140768)
When a TYPE(*) dummy argument is erroneously used as a component value in a structure constructor, semantics crashes if the structure constructor had been initially parsed as a potential function reference. Clean out stale typed expressions when reanalyzing the reconstructed parse subtree to ensure that errors are caught the next time around.
This commit is contained in:
parent
4c6b60a639
commit
ff8288442d
@ -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());
|
||||
}
|
||||
}
|
||||
@ -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);
|
||||
|
10
flang/test/Semantics/bug869.f90
Normal file
10
flang/test/Semantics/bug869.f90
Normal file
@ -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
|
Loading…
x
Reference in New Issue
Block a user