[flang-commits] [flang] [flang] Don't convert actual arguments when interface is implicit (PR #89795)
Peter Klausler via flang-commits
flang-commits at lists.llvm.org
Tue Apr 23 10:08:54 PDT 2024
https://github.com/klausler created https://github.com/llvm/llvm-project/pull/89795
When the interface of a procedure is implicit at the point of call, don't perform actual argument type conversion to the types of the dummy arguments. This was inadvertently taking place in a case where the procedure has an implicit interface but was also defined in the same source file, so that its characteristics were known.
>From 45c9f59ad6a66053baee38442f64807e406dae85 Mon Sep 17 00:00:00 2001
From: Peter Klausler <pklausler at nvidia.com>
Date: Tue, 23 Apr 2024 10:05:55 -0700
Subject: [PATCH] [flang] Don't convert actual arguments when interface is
implicit
When the interface of a procedure is implicit at the point of call,
don't perform actual argument type conversion to the types of the
dummy arguments. This was inadvertently taking place in a case
where the procedure has an implicit interface but was also defined
in the same source file, so that its characteristics were known.
---
flang/lib/Semantics/check-call.cpp | 6 ++++--
flang/lib/Semantics/expression.cpp | 4 ++--
flang/test/Semantics/arg-convert.f90 | 16 ++++++++++++++++
3 files changed, 22 insertions(+), 4 deletions(-)
create mode 100644 flang/test/Semantics/arg-convert.f90
diff --git a/flang/lib/Semantics/check-call.cpp b/flang/lib/Semantics/check-call.cpp
index ce82cccf26d546..db0949e905a658 100644
--- a/flang/lib/Semantics/check-call.cpp
+++ b/flang/lib/Semantics/check-call.cpp
@@ -1929,6 +1929,7 @@ bool CheckArguments(const characteristics::Procedure &proc,
bool explicitInterface{proc.HasExplicitInterface()};
evaluate::FoldingContext foldingContext{context.foldingContext()};
parser::ContextualMessages &messages{foldingContext.messages()};
+ bool allowArgumentConversions{true};
if (!explicitInterface || treatingExternalAsImplicit) {
parser::Messages buffer;
{
@@ -1945,11 +1946,12 @@ bool CheckArguments(const characteristics::Procedure &proc,
}
return false; // don't pile on
}
+ allowArgumentConversions = false;
}
if (explicitInterface) {
auto buffer{CheckExplicitInterface(proc, actuals, context, &scope,
- intrinsic, /*allowArgumentConversions=*/true, /*extentErrors=*/true,
- ignoreImplicitVsExplicit)};
+ intrinsic, allowArgumentConversions,
+ /*extentErrors=*/true, ignoreImplicitVsExplicit)};
if (!buffer.empty()) {
if (treatingExternalAsImplicit) {
if (auto *msg{messages.Say(
diff --git a/flang/lib/Semantics/expression.cpp b/flang/lib/Semantics/expression.cpp
index a270e4b385e8db..b8396209fc6854 100644
--- a/flang/lib/Semantics/expression.cpp
+++ b/flang/lib/Semantics/expression.cpp
@@ -2989,8 +2989,8 @@ void ExpressionAnalyzer::Analyze(const parser::CallStmt &callStmt) {
for (const auto &arg : actualArgList) {
analyzer.Analyze(arg, true /* is subroutine call */);
}
- auto chevrons{AnalyzeChevrons(callStmt)};
- if (!analyzer.fatalErrors() && chevrons) {
+ if (auto chevrons{AnalyzeChevrons(callStmt)};
+ chevrons && !analyzer.fatalErrors()) {
if (std::optional<CalleeAndArguments> callee{
GetCalleeAndArguments(std::get<parser::ProcedureDesignator>(call.t),
analyzer.GetActuals(), true /* subroutine */)}) {
diff --git a/flang/test/Semantics/arg-convert.f90 b/flang/test/Semantics/arg-convert.f90
new file mode 100644
index 00000000000000..7951bedf49d0f8
--- /dev/null
+++ b/flang/test/Semantics/arg-convert.f90
@@ -0,0 +1,16 @@
+!RUN: %flang_fc1 -fdebug-unparse %s 2>&1 | FileCheck %s
+!Ensure that argument conversion does not take place when the procedure
+!interface is implicit at the point of call, even when the interface
+!is known due because the procedure's definition is in the same source file.
+
+subroutine test
+!CHECK: warning: If the procedure's interface were explicit, this reference would be in error
+!CHECK: because: Actual argument type 'INTEGER(8)' is not compatible with dummy argument type 'INTEGER(4)'
+!CHECK: CALL samesourcefile((1_8))
+ call sameSourceFile((1_8))
+!CHECK: CALL somewhereelse((2_8))
+ call somewhereElse((2_8))
+end
+
+subroutine sameSourceFile(n)
+end
More information about the flang-commits
mailing list