[flang-commits] [flang] [flang] Silence confusing spurious error message (PR #183105)
Peter Klausler via flang-commits
flang-commits at lists.llvm.org
Tue Feb 24 09:12:43 PST 2026
https://github.com/klausler created https://github.com/llvm/llvm-project/pull/183105
The procedure characterization module unconditionally emits a "'foobar' is not a procedure" when asked to analyze a symbol that is, well, not a procedure -- even when called with a flag to suppress errors from analysis, since the calling context is going to handle failure. This leads to some error messages that have source positions completely unrelated to the symbol in question. Make this error sensitive to the suppression flag.
>From 4c341411468665c9ec58f8ca33ac851d634cf6db Mon Sep 17 00:00:00 2001
From: Peter Klausler <pklausler at nvidia.com>
Date: Tue, 24 Feb 2026 09:08:30 -0800
Subject: [PATCH] [flang] Silence confusing spurious error message
The procedure characterization module unconditionally emits a
"'foobar' is not a procedure" when asked to analyze a symbol
that is, well, not a procedure -- even when called with a flag
to suppress errors from analysis, since the calling context is
going to handle failure. This leads to some error messages
that have source positions completely unrelated to the symbol
in question. Make this error sensitive to the suppression flag.
---
flang/lib/Evaluate/characteristics.cpp | 9 +++++----
flang/test/Semantics/associated.f90 | 1 -
flang/test/Semantics/bug2273.f90 | 10 ++++++++++
3 files changed, 15 insertions(+), 5 deletions(-)
create mode 100644 flang/test/Semantics/bug2273.f90
diff --git a/flang/lib/Evaluate/characteristics.cpp b/flang/lib/Evaluate/characteristics.cpp
index 65495e5eff219..50f5f91fe60d6 100644
--- a/flang/lib/Evaluate/characteristics.cpp
+++ b/flang/lib/Evaluate/characteristics.cpp
@@ -625,8 +625,7 @@ static std::optional<Procedure> CharacterizeProcedure(
if (seenProcs.find(symbol) != seenProcs.end()) {
std::string procsList{GetSeenProcs(seenProcs)};
context.messages().Say(symbol.name(),
- "Procedure '%s' is recursively defined. Procedures in the cycle:"
- " %s"_err_en_US,
+ "Procedure '%s' is recursively defined. Procedures in the cycle: %s"_err_en_US,
symbol.name(), procsList);
return std::nullopt;
}
@@ -776,8 +775,10 @@ static std::optional<Procedure> CharacterizeProcedure(
return std::optional<Procedure>{};
},
[&](const auto &) {
- context.messages().Say(
- "'%s' is not a procedure"_err_en_US, symbol.name());
+ if (emitError) {
+ context.messages().Say(
+ "'%s' is not a procedure"_err_en_US, symbol.name());
+ }
return std::optional<Procedure>{};
},
},
diff --git a/flang/test/Semantics/associated.f90 b/flang/test/Semantics/associated.f90
index 731f2d828995f..4620c73130974 100644
--- a/flang/test/Semantics/associated.f90
+++ b/flang/test/Semantics/associated.f90
@@ -251,7 +251,6 @@ 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'
lvar = associated(badPointer)
end subroutine test
diff --git a/flang/test/Semantics/bug2273.f90 b/flang/test/Semantics/bug2273.f90
new file mode 100644
index 0000000000000..9d16bc91749ce
--- /dev/null
+++ b/flang/test/Semantics/bug2273.f90
@@ -0,0 +1,10 @@
+!RUN: %python %S/test_errors.py %s %flang_fc1
+module m
+ type dt
+ end type
+ contains
+ subroutine s(p)
+ !ERROR: 'dt' must be an abstract interface or a procedure with an explicit interface
+ procedure(dt), pointer :: p
+ end
+end
More information about the flang-commits
mailing list