[flang-commits] [flang] 056ae8b - [flang] Correctly buffer warnings in Semantics/check-call.cpp (#172738)
via flang-commits
flang-commits at lists.llvm.org
Fri Dec 19 14:32:39 PST 2025
Author: Peter Klausler
Date: 2025-12-19T14:32:35-08:00
New Revision: 056ae8bab6df825952a24633c197128f3adf5d5f
URL: https://github.com/llvm/llvm-project/commit/056ae8bab6df825952a24633c197128f3adf5d5f
DIFF: https://github.com/llvm/llvm-project/commit/056ae8bab6df825952a24633c197128f3adf5d5f.diff
LOG: [flang] Correctly buffer warnings in Semantics/check-call.cpp (#172738)
There are calls to semantics::SemanticsContext::Warn() in check-call.cpp
that are not properly directing their output to the local message
buffer, so they can appear unconditionally in the output of the
compiler. This is a problem for generic interface resolution, which
checks procedure actual arguments against specific procedures using this
code, buffering the messages that might appear, and discarding the
messages for failed matches. Worse, the bogus warnings that escape the
buffering can be associated with completely unrelated locations.
Fix by passing the local message buffer to these Warn() calls.
(I couldn't come up with a good reduced test case, and am not sure that
the original code can be copied for use as one.)
Added:
Modified:
flang/lib/Semantics/check-call.cpp
Removed:
################################################################################
diff --git a/flang/lib/Semantics/check-call.cpp b/flang/lib/Semantics/check-call.cpp
index 022b4289b4e7c..5f276d9b9f4f8 100644
--- a/flang/lib/Semantics/check-call.cpp
+++ b/flang/lib/Semantics/check-call.cpp
@@ -610,9 +610,8 @@ static void CheckExplicitDataArg(const characteristics::DummyDataObject &dummy,
!dummy.ignoreTKR.test(common::IgnoreTKR::Contiguous)) {
if (IsPointer(*actualLastSymbol)) {
if (isOkBecauseContiguous) {
- context.Warn(
+ foldingContext.Warn(
common::LanguageFeature::ContiguousOkForSeqAssociation,
- messages.at(),
"Element of contiguous pointer array is accepted for storage sequence association"_port_en_US);
} else {
basicError = true;
@@ -623,9 +622,8 @@ static void CheckExplicitDataArg(const characteristics::DummyDataObject &dummy,
} else if (IsAssumedShape(*actualLastSymbol) &&
!dummy.ignoreTKR.test(common::IgnoreTKR::Contiguous)) {
if (isOkBecauseContiguous) {
- context.Warn(
+ foldingContext.Warn(
common::LanguageFeature::ContiguousOkForSeqAssociation,
- messages.at(),
"Element of contiguous assumed-shape array is accepted for storage sequence association"_port_en_US);
} else {
basicError = true;
@@ -653,9 +651,8 @@ static void CheckExplicitDataArg(const characteristics::DummyDataObject &dummy,
messages.Say(
"Assumed-rank array may not be associated with a dummy argument that is not assumed-rank"_err_en_US);
} else {
- context.Warn(
+ foldingContext.Warn(
common::LanguageFeature::AssumedRankPassedToNonAssumedRank,
- messages.at(),
"Assumed-rank array should not be associated with a dummy argument that is not assumed-rank"_port_en_US);
}
} else if (actualRank == 0) {
@@ -693,7 +690,7 @@ static void CheckExplicitDataArg(const characteristics::DummyDataObject &dummy,
static_cast<std::intmax_t>(*actualElements), dummyName,
static_cast<std::intmax_t>(*dummySize));
} else {
- context.Warn(common::UsageWarning::ShortArrayActual,
+ foldingContext.Warn(common::UsageWarning::ShortArrayActual,
"Actual argument has fewer elements remaining in storage sequence (%jd) than %s array (%jd)"_warn_en_US,
static_cast<std::intmax_t>(*actualElements), dummyName,
static_cast<std::intmax_t>(*dummySize));
@@ -711,7 +708,7 @@ static void CheckExplicitDataArg(const characteristics::DummyDataObject &dummy,
static_cast<std::intmax_t>(*actualSize), dummyName,
static_cast<std::intmax_t>(*dummySize));
} else {
- context.Warn(common::UsageWarning::ShortArrayActual,
+ foldingContext.Warn(common::UsageWarning::ShortArrayActual,
"Actual argument array has fewer elements (%jd) than %s array (%jd)"_warn_en_US,
static_cast<std::intmax_t>(*actualSize), dummyName,
static_cast<std::intmax_t>(*dummySize));
@@ -826,8 +823,7 @@ static void CheckExplicitDataArg(const characteristics::DummyDataObject &dummy,
(actualIsPointer && dummyIsPointer)) &&
evaluate::IsArraySection(actual) && !actualIsContiguous &&
!evaluate::HasVectorSubscript(actual)) {
- context.Warn(common::UsageWarning::VolatileOrAsynchronousTemporary,
- messages.at(),
+ foldingContext.Warn(common::UsageWarning::VolatileOrAsynchronousTemporary,
"The array section '%s' should not be associated with %s with %s attribute, unless the dummy is assumed-shape or assumed-rank"_warn_en_US,
actual.AsFortran(), dummyName,
dummyIsAsynchronous ? "ASYNCHRONOUS" : "VOLATILE");
@@ -844,8 +840,7 @@ static void CheckExplicitDataArg(const characteristics::DummyDataObject &dummy,
if (copyOutNeeded && !volatileOrAsyncNeedsTempDiagnosticIssued) {
if ((actualIsVolatile || actualIsAsynchronous) &&
(dummyIsVolatile || dummyIsAsynchronous)) {
- context.Warn(common::UsageWarning::VolatileOrAsynchronousTemporary,
- messages.at(),
+ foldingContext.Warn(common::UsageWarning::VolatileOrAsynchronousTemporary,
"The actual argument '%s' with %s attribute should not be associated with %s with %s attribute, because a temporary copy is required during the call"_warn_en_US,
actual.AsFortran(), actualIsVolatile ? "VOLATILE" : "ASYNCHRONOUS",
dummyName, dummyIsVolatile ? "VOLATILE" : "ASYNCHRONOUS");
@@ -863,7 +858,7 @@ static void CheckExplicitDataArg(const characteristics::DummyDataObject &dummy,
(actualIsPointer && dummyIsPointer)) &&
evaluate::IsArraySection(actual) &&
!evaluate::HasVectorSubscript(actual)) {
- context.Warn(common::UsageWarning::Portability, messages.at(),
+ foldingContext.Warn(common::UsageWarning::Portability,
"The array section '%s' should not be associated with %s with %s attribute, unless the dummy is assumed-shape or assumed-rank"_port_en_US,
actual.AsFortran(), dummyName,
dummyIsAsynchronous ? "ASYNCHRONOUS" : "VOLATILE");
@@ -872,7 +867,7 @@ static void CheckExplicitDataArg(const characteristics::DummyDataObject &dummy,
if (copyOutNeeded && !volatileOrAsyncNeedsTempDiagnosticIssued) {
if ((dummyIsVolatile && !actualIsVolatile && !actualIsAsynchronous) ||
(dummyIsAsynchronous && !actualIsVolatile && !actualIsAsynchronous)) {
- context.Warn(common::UsageWarning::Portability, messages.at(),
+ foldingContext.Warn(common::UsageWarning::Portability,
"The actual argument '%s' should not be associated with %s with %s attribute, because a temporary copy is required during the call"_port_en_US,
actual.AsFortran(), dummyName,
dummyIsVolatile ? "VOLATILE" : "ASYNCHRONOUS");
@@ -2437,7 +2432,7 @@ bool CheckArguments(const characteristics::Procedure &proc,
intrinsic, allowArgumentConversions,
/*extentErrors=*/true, ignoreImplicitVsExplicit)};
if (!explicitBuffer.empty()) {
- if (treatingExternalAsImplicit) {
+ if (treatingExternalAsImplicit && explicitBuffer.AnyFatalError()) {
// Combine all messages into one warning
if (auto *warning{messages.Warn(/*inModuleFile=*/false,
context.languageFeatures(),
More information about the flang-commits
mailing list