[flang-commits] [flang] ad778a8 - [flang] Better error recovery when using erroneous procedures and pointers as intrinsic actual arguments
Peter Klausler via flang-commits
flang-commits at lists.llvm.org
Tue Aug 29 08:20:39 PDT 2023
Author: Peter Klausler
Date: 2023-08-29T08:20:27-07:00
New Revision: ad778a8a0ffd0ab54673c04c196ce8192ea15e6f
URL: https://github.com/llvm/llvm-project/commit/ad778a8a0ffd0ab54673c04c196ce8192ea15e6f
DIFF: https://github.com/llvm/llvm-project/commit/ad778a8a0ffd0ab54673c04c196ce8192ea15e6f.diff
LOG: [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
Added:
Modified:
flang/lib/Evaluate/intrinsics.cpp
flang/test/Semantics/associated.f90
Removed:
################################################################################
diff --git a/flang/lib/Evaluate/intrinsics.cpp b/flang/lib/Evaluate/intrinsics.cpp
index aa0d349ad5e88f..67c68dd9d7941c 100644
--- a/flang/lib/Evaluate/intrinsics.cpp
+++ b/flang/lib/Evaluate/intrinsics.cpp
@@ -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},
diff --git a/flang/test/Semantics/associated.f90 b/flang/test/Semantics/associated.f90
index f96d93b37bc903..7229f8ad4ece09 100644
--- a/flang/test/Semantics/associated.f90
+++ b/flang/test/Semantics/associated.f90
@@ -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
@@ -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
More information about the flang-commits
mailing list