[flang-commits] [flang] [flang] Reject type bound procedure overrides with mismatched passed-object dummy names (PR #210876)
via flang-commits
flang-commits at lists.llvm.org
Mon Jul 20 22:15:13 PDT 2026
https://github.com/ejose02 updated https://github.com/llvm/llvm-project/pull/210876
>From a9bd9439c86fdbf25e47c336897c5cde563d46de Mon Sep 17 00:00:00 2001
From: ejose <ejose at amd.com>
Date: Tue, 21 Jul 2026 05:05:55 +0000
Subject: [PATCH] [flang] Reject type bound procedure overrides with mismatched
passed-object dummy names
Fixes #206913
Issue:
Flang wrongly accepts a type-bound procedure override when the implementing procedure uses a different dummy name than the parent deferred interface.
Root cause:
The PASS override check uses CanOverride, which compares dummy types but not dummy names for the passed-object argument.
Fix:
Check that dummy names match before CanOverride and report a clear error
---
flang/lib/Semantics/check-declarations.cpp | 20 +++++++++++++++++
flang/test/Semantics/bindings08.f90 | 25 ++++++++++++++++++++++
2 files changed, 45 insertions(+)
create mode 100644 flang/test/Semantics/bindings08.f90
diff --git a/flang/lib/Semantics/check-declarations.cpp b/flang/lib/Semantics/check-declarations.cpp
index 0a62e199d9779..bdd12811c00b8 100644
--- a/flang/lib/Semantics/check-declarations.cpp
+++ b/flang/lib/Semantics/check-declarations.cpp
@@ -2700,6 +2700,19 @@ void CheckHelper::CheckPassArg(
}
}
+static bool OverrideDummyNamesMatch(
+ const Procedure &binding, const Procedure &overridden) {
+ if (binding.dummyArguments.size() != overridden.dummyArguments.size()) {
+ return false;
+ }
+ for (std::size_t j{0}; j < binding.dummyArguments.size(); ++j) {
+ if (binding.dummyArguments[j].name != overridden.dummyArguments[j].name) {
+ return false;
+ }
+ }
+ return true;
+}
+
void CheckHelper::CheckProcBinding(
const Symbol &symbol, const ProcBindingDetails &binding) {
const Scope &dtScope{symbol.owner()};
@@ -2783,6 +2796,13 @@ void CheckHelper::CheckProcBinding(
if (*passIndex != *overriddenPassIndex) {
SayWithDeclaration(*overridden,
"A type-bound procedure and its override must use the same PASS argument"_err_en_US);
+ } else if (!OverrideDummyNamesMatch(
+ *bindingChars, *overriddenChars)) {
+ SayWithDeclaration(*overridden,
+ "Passed-object dummy arguments of type-bound procedure "
+ "'%s' "
+ "and its override must correspond by name and position"_err_en_US,
+ symbol.name());
} else if (!bindingChars->CanOverride(
*overriddenChars, passIndex)) {
SayWithDeclaration(*overridden,
diff --git a/flang/test/Semantics/bindings08.f90 b/flang/test/Semantics/bindings08.f90
new file mode 100644
index 0000000000000..4542e0091a0c9
--- /dev/null
+++ b/flang/test/Semantics/bindings08.f90
@@ -0,0 +1,25 @@
+! RUN: %python %S/test_errors.py %s %flang_fc1
+
+module m
+ type, abstract :: parent
+ contains
+ procedure(ip), deferred :: set
+ end type
+ abstract interface
+ subroutine ip(x)
+ import parent
+ class(parent) :: x
+ end subroutine
+ end interface
+ type, public, extends(parent), abstract :: child
+ end type
+ type, extends(child) :: grandchild
+ contains
+ !ERROR: Passed-object dummy arguments of type-bound procedure 'set' and its override must correspond by name and position
+ procedure :: set
+ end type
+ contains
+ subroutine set(y)
+ class(grandchild) :: y
+ end subroutine
+end module
More information about the flang-commits
mailing list