[flang] Better error recovery when using erroneous procedures and pointers as intrinsic actual arguments

Instead of crashing with an internal error when a procedure or
procedure pointer with a badly declared interface is presented to
an intrinsic procedure like ASSOCIATED, emit an error message
and continue with compilation.

Differential Revision: https://reviews.llvm.org/D159028
This commit is contained in:
Peter Klausler 2023-08-15 16:29:30 -07:00
parent 41cb3c4d87
commit ad778a8a0f
No known key found for this signature in database
2 changed files with 16 additions and 9 deletions

View File

@ -2320,18 +2320,18 @@ std::optional<SpecificCall> IntrinsicInterface::Match(
}
}
}
auto dc{characteristics::DummyArgument::FromActual(
std::move(kw), *expr, context)};
if (!dc) {
common::die("INTERNAL: could not characterize intrinsic function "
"actual argument '%s'",
if (auto dc{characteristics::DummyArgument::FromActual(
std::move(kw), *expr, context)}) {
dummyArgs.emplace_back(std::move(*dc));
if (d.typePattern.kindCode == KindCode::same && !sameDummyArg) {
sameDummyArg = j;
}
} else { // error recovery
messages.Say(
"Could not characterize intrinsic function actual argument '%s'"_err_en_US,
expr->AsFortran().c_str());
return std::nullopt;
}
dummyArgs.emplace_back(std::move(*dc));
if (d.typePattern.kindCode == KindCode::same && !sameDummyArg) {
sameDummyArg = j;
}
} else {
CHECK(arg->GetAssumedTypeDummy());
dummyArgs.emplace_back(std::string{d.keyword},

View File

@ -70,6 +70,8 @@ subroutine assoc()
procedure(subrInt), pointer :: subProcPointer
procedure(), pointer :: implicitProcPointer
procedure(subrCannotBeCalledfromImplicit), pointer :: cannotBeCalledfromImplicitPointer
!ERROR: 'neverdeclared' must be an abstract interface or a procedure with an explicit interface
procedure(neverDeclared), pointer :: badPointer
logical :: lVar
type(t1) :: t1x
type(t1), target :: t1xtarget
@ -210,5 +212,10 @@ subroutine assoc()
lvar = associated(intPointerArr, targetIntArr([2,1]))
!ERROR: TARGET= argument 'targetintcoarray[1_8]' may not have a vector subscript or coindexing
lvar = associated(intPointerVar1, targetIntCoarray[1])
!ERROR: 'neverdeclared' is not a procedure
!ERROR: Could not characterize intrinsic function actual argument 'badpointer'
!ERROR: 'neverdeclared' is not a procedure
!ERROR: Could not characterize intrinsic function actual argument 'badpointer'
lvar = associated(badPointer)
end subroutine test
end subroutine assoc