Skip to content

Commit 056ae8b

Browse files
authored
[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.)
1 parent 79670f1 commit 056ae8b

File tree

1 file changed

+10
-15
lines changed

1 file changed

+10
-15
lines changed

flang/lib/Semantics/check-call.cpp

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -610,9 +610,8 @@ static void CheckExplicitDataArg(const characteristics::DummyDataObject &dummy,
610610
!dummy.ignoreTKR.test(common::IgnoreTKR::Contiguous)) {
611611
if (IsPointer(*actualLastSymbol)) {
612612
if (isOkBecauseContiguous) {
613-
context.Warn(
613+
foldingContext.Warn(
614614
common::LanguageFeature::ContiguousOkForSeqAssociation,
615-
messages.at(),
616615
"Element of contiguous pointer array is accepted for storage sequence association"_port_en_US);
617616
} else {
618617
basicError = true;
@@ -623,9 +622,8 @@ static void CheckExplicitDataArg(const characteristics::DummyDataObject &dummy,
623622
} else if (IsAssumedShape(*actualLastSymbol) &&
624623
!dummy.ignoreTKR.test(common::IgnoreTKR::Contiguous)) {
625624
if (isOkBecauseContiguous) {
626-
context.Warn(
625+
foldingContext.Warn(
627626
common::LanguageFeature::ContiguousOkForSeqAssociation,
628-
messages.at(),
629627
"Element of contiguous assumed-shape array is accepted for storage sequence association"_port_en_US);
630628
} else {
631629
basicError = true;
@@ -653,9 +651,8 @@ static void CheckExplicitDataArg(const characteristics::DummyDataObject &dummy,
653651
messages.Say(
654652
"Assumed-rank array may not be associated with a dummy argument that is not assumed-rank"_err_en_US);
655653
} else {
656-
context.Warn(
654+
foldingContext.Warn(
657655
common::LanguageFeature::AssumedRankPassedToNonAssumedRank,
658-
messages.at(),
659656
"Assumed-rank array should not be associated with a dummy argument that is not assumed-rank"_port_en_US);
660657
}
661658
} else if (actualRank == 0) {
@@ -693,7 +690,7 @@ static void CheckExplicitDataArg(const characteristics::DummyDataObject &dummy,
693690
static_cast<std::intmax_t>(*actualElements), dummyName,
694691
static_cast<std::intmax_t>(*dummySize));
695692
} else {
696-
context.Warn(common::UsageWarning::ShortArrayActual,
693+
foldingContext.Warn(common::UsageWarning::ShortArrayActual,
697694
"Actual argument has fewer elements remaining in storage sequence (%jd) than %s array (%jd)"_warn_en_US,
698695
static_cast<std::intmax_t>(*actualElements), dummyName,
699696
static_cast<std::intmax_t>(*dummySize));
@@ -711,7 +708,7 @@ static void CheckExplicitDataArg(const characteristics::DummyDataObject &dummy,
711708
static_cast<std::intmax_t>(*actualSize), dummyName,
712709
static_cast<std::intmax_t>(*dummySize));
713710
} else {
714-
context.Warn(common::UsageWarning::ShortArrayActual,
711+
foldingContext.Warn(common::UsageWarning::ShortArrayActual,
715712
"Actual argument array has fewer elements (%jd) than %s array (%jd)"_warn_en_US,
716713
static_cast<std::intmax_t>(*actualSize), dummyName,
717714
static_cast<std::intmax_t>(*dummySize));
@@ -826,8 +823,7 @@ static void CheckExplicitDataArg(const characteristics::DummyDataObject &dummy,
826823
(actualIsPointer && dummyIsPointer)) &&
827824
evaluate::IsArraySection(actual) && !actualIsContiguous &&
828825
!evaluate::HasVectorSubscript(actual)) {
829-
context.Warn(common::UsageWarning::VolatileOrAsynchronousTemporary,
830-
messages.at(),
826+
foldingContext.Warn(common::UsageWarning::VolatileOrAsynchronousTemporary,
831827
"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,
832828
actual.AsFortran(), dummyName,
833829
dummyIsAsynchronous ? "ASYNCHRONOUS" : "VOLATILE");
@@ -844,8 +840,7 @@ static void CheckExplicitDataArg(const characteristics::DummyDataObject &dummy,
844840
if (copyOutNeeded && !volatileOrAsyncNeedsTempDiagnosticIssued) {
845841
if ((actualIsVolatile || actualIsAsynchronous) &&
846842
(dummyIsVolatile || dummyIsAsynchronous)) {
847-
context.Warn(common::UsageWarning::VolatileOrAsynchronousTemporary,
848-
messages.at(),
843+
foldingContext.Warn(common::UsageWarning::VolatileOrAsynchronousTemporary,
849844
"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,
850845
actual.AsFortran(), actualIsVolatile ? "VOLATILE" : "ASYNCHRONOUS",
851846
dummyName, dummyIsVolatile ? "VOLATILE" : "ASYNCHRONOUS");
@@ -863,7 +858,7 @@ static void CheckExplicitDataArg(const characteristics::DummyDataObject &dummy,
863858
(actualIsPointer && dummyIsPointer)) &&
864859
evaluate::IsArraySection(actual) &&
865860
!evaluate::HasVectorSubscript(actual)) {
866-
context.Warn(common::UsageWarning::Portability, messages.at(),
861+
foldingContext.Warn(common::UsageWarning::Portability,
867862
"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,
868863
actual.AsFortran(), dummyName,
869864
dummyIsAsynchronous ? "ASYNCHRONOUS" : "VOLATILE");
@@ -872,7 +867,7 @@ static void CheckExplicitDataArg(const characteristics::DummyDataObject &dummy,
872867
if (copyOutNeeded && !volatileOrAsyncNeedsTempDiagnosticIssued) {
873868
if ((dummyIsVolatile && !actualIsVolatile && !actualIsAsynchronous) ||
874869
(dummyIsAsynchronous && !actualIsVolatile && !actualIsAsynchronous)) {
875-
context.Warn(common::UsageWarning::Portability, messages.at(),
870+
foldingContext.Warn(common::UsageWarning::Portability,
876871
"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,
877872
actual.AsFortran(), dummyName,
878873
dummyIsVolatile ? "VOLATILE" : "ASYNCHRONOUS");
@@ -2437,7 +2432,7 @@ bool CheckArguments(const characteristics::Procedure &proc,
24372432
intrinsic, allowArgumentConversions,
24382433
/*extentErrors=*/true, ignoreImplicitVsExplicit)};
24392434
if (!explicitBuffer.empty()) {
2440-
if (treatingExternalAsImplicit) {
2435+
if (treatingExternalAsImplicit && explicitBuffer.AnyFatalError()) {
24412436
// Combine all messages into one warning
24422437
if (auto *warning{messages.Warn(/*inModuleFile=*/false,
24432438
context.languageFeatures(),

0 commit comments

Comments
 (0)