[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:18 PDT 2026
https://github.com/keepyixiao created https://github.com/llvm/llvm-project/pull/233225
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
>From ca4c1ee24b48688728fb21ee47555db33fa5d957 Mon Sep 17 00:00:00 2001
From: nudt_yixiao <1272950933 at qq.com>
Date: Sun, 18 Oct 2026 16:01:30 +0800
Subject: [PATCH] [Flang] Diagnose recursive abstract procedure interfaces
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.
---
flang/lib/Semantics/check-declarations.cpp | 9 +++++----
flang/test/Semantics/resolve102.f90 | 14 ++++++++++++++
2 files changed, 19 insertions(+), 4 deletions(-)
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
More information about the flang-commits
mailing list