[flang-commits] [flang] [Flang] Diagnose recursive abstract procedure interfaces (PR #233225)
via flang-commits
flang-commits at lists.llvm.org
Sun Oct 18 05:56:54 PDT 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-flang-semantics
Author: nudt_yixiao (keepyixiao)
<details>
<summary>Changes</summary>
Recursive abstract procedure interfaces could remain unchecked until lowering, where failed procedure characterization caused a compiler crash.
Check interface body characteristics during declaration checking so that recursive interfaces are diagnosed before lowering.
Add a regression test for a recursive abstract interface used by a procedure pointer.
Fixes https://github.com/llvm/llvm-project/issues/230862
---
Full diff: https://github.com/llvm/llvm-project/pull/233225.diff
2 Files Affected:
- (modified) flang/lib/Semantics/check-declarations.cpp (+5-4)
- (modified) flang/test/Semantics/resolve102.f90 (+14)
``````````diff
diff --git a/flang/lib/Semantics/check-declarations.cpp b/flang/lib/Semantics/check-declarations.cpp
index 2abefd381850ad..0234d50cf53b35 100644
--- a/flang/lib/Semantics/check-declarations.cpp
+++ b/flang/lib/Semantics/check-declarations.cpp
@@ -1614,11 +1614,12 @@ bool CheckHelper::IsResultOkToDiffer(const FunctionResult &result) {
void CheckHelper::CheckSubprogram(
const Symbol &symbol, const SubprogramDetails &details) {
- // Evaluate a procedure definition's characteristics to flush out
- // any errors that analysis might expose, in case this subprogram hasn't
- // had any calls in this compilation unit that would have validated them.
+ // Evaluate a procedure definition or interface body's characteristics to
+ // flush out any errors that analysis might expose, in case this subprogram
+ // hasn't had any calls in this compilation unit that would have validated
+ // them.
if (!context_.HasError(symbol) && !details.isDummy() &&
- !details.isInterface() && !details.stmtFunction()) {
+ !details.stmtFunction()) {
if (!Procedure::Characterize(symbol, foldingContext_)) {
context_.SetError(symbol);
}
diff --git a/flang/test/Semantics/resolve102.f90 b/flang/test/Semantics/resolve102.f90
index 62b0c5d3a21b34..39bcb1aed2cb07 100644
--- a/flang/test/Semantics/resolve102.f90
+++ b/flang/test/Semantics/resolve102.f90
@@ -6,6 +6,20 @@ subroutine sub(p2)
PROCEDURE(sub) :: p2
end subroutine
+module recursiveAbstractInterface
+ implicit none
+ abstract interface
+ !ERROR: Procedure 'cb' is recursively defined. Procedures in the cycle: 'cb', 'next'
+ subroutine cb(next)
+ procedure(cb) :: next
+ end subroutine
+ end interface
+end module
+
+use recursiveAbstractInterface, only: cb
+procedure(cb), pointer :: callback => null()
+end
+
subroutine circular
procedure(sub) :: p
contains
``````````
</details>
https://github.com/llvm/llvm-project/pull/233225
More information about the flang-commits
mailing list