[flang-commits] [flang] [flang] Silence confusing spurious error message (PR #183105)
via flang-commits
flang-commits at lists.llvm.org
Tue Feb 24 09:13:18 PST 2026
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-flang-semantics
Author: Peter Klausler (klausler)
<details>
<summary>Changes</summary>
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.
---
Full diff: https://github.com/llvm/llvm-project/pull/183105.diff
3 Files Affected:
- (modified) flang/lib/Evaluate/characteristics.cpp (+5-4)
- (modified) flang/test/Semantics/associated.f90 (-1)
- (added) flang/test/Semantics/bug2273.f90 (+10)
``````````diff
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
``````````
</details>
https://github.com/llvm/llvm-project/pull/183105
More information about the flang-commits
mailing list