Skip to content

Commit

Permalink
[flang] Better error recovery when using erroneous procedures and poi…
Browse files Browse the repository at this point in the history
…nters 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
  • Loading branch information
klausler committed Aug 29, 2023
1 parent 41cb3c4 commit ad778a8
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
18 changes: 9 additions & 9 deletions flang/lib/Evaluate/intrinsics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down
7 changes: 7 additions & 0 deletions flang/test/Semantics/associated.f90
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ subroutine test(assumedRank)
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
Expand Down Expand Up @@ -210,5 +212,10 @@ subroutine test(assumedRank)
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

0 comments on commit ad778a8

Please sign in to comment.