[flang-commits] [flang] [flang] Silence warning when inappropriate (PR #105867)

Peter Klausler via flang-commits flang-commits at lists.llvm.org
Fri Aug 23 11:06:31 PDT 2024


https://github.com/klausler created https://github.com/llvm/llvm-project/pull/105867

When a function returns an array, using an element of that array is an actual argument in a procedure reference with an implicit interface should suffice to avoid a warning about an undefined function result.

>From ddf033a3e34702e693ccc7037cb6162c8bee38fa Mon Sep 17 00:00:00 2001
From: Peter Klausler <pklausler at nvidia.com>
Date: Fri, 23 Aug 2024 11:04:12 -0700
Subject: [PATCH] [flang] Silence warning when inappropriate

When a function returns an array, using an element of that
array is an actual argument in a procedure reference with an
implicit interface should suffice to avoid a warning about an
undefined function result.
---
 flang/lib/Semantics/check-call.cpp      | 8 ++++----
 flang/test/Semantics/undef-result01.f90 | 5 +++++
 2 files changed, 9 insertions(+), 4 deletions(-)

diff --git a/flang/lib/Semantics/check-call.cpp b/flang/lib/Semantics/check-call.cpp
index 4708d51d3af4dd..c7ec8733655648 100644
--- a/flang/lib/Semantics/check-call.cpp
+++ b/flang/lib/Semantics/check-call.cpp
@@ -56,6 +56,10 @@ static void CheckImplicitInterfaceArg(evaluate::ActualArgument &arg,
         "%VAL argument must be a scalar numeric or logical expression"_err_en_US);
   }
   if (const auto *expr{arg.UnwrapExpr()}) {
+    if (const Symbol * base{GetFirstSymbol(*expr)};
+        base && IsFunctionResult(*base)) {
+      context.NoteDefinedSymbol(*base);
+    }
     if (IsBOZLiteral(*expr)) {
       messages.Say("BOZ argument requires an explicit interface"_err_en_US);
     } else if (evaluate::IsNullPointer(*expr)) {
@@ -79,10 +83,6 @@ static void CheckImplicitInterfaceArg(evaluate::ActualArgument &arg,
         messages.Say(
             "VOLATILE argument requires an explicit interface"_err_en_US);
       }
-      if (const Symbol & base{named->GetFirstSymbol()};
-          IsFunctionResult(base)) {
-        context.NoteDefinedSymbol(base);
-      }
     } else if (auto argChars{characteristics::DummyArgument::FromActual(
                    "actual argument", *expr, context.foldingContext(),
                    /*forImplicitInterface=*/true)}) {
diff --git a/flang/test/Semantics/undef-result01.f90 b/flang/test/Semantics/undef-result01.f90
index bf6af11a8d7b92..08e7fe1e448998 100644
--- a/flang/test/Semantics/undef-result01.f90
+++ b/flang/test/Semantics/undef-result01.f90
@@ -148,3 +148,8 @@ function defdByAssociate()
     s = 1.
   end associate
 end
+
+function defdByElementArgToImplicit() result(r)
+  real r(1)
+  call define(r(1))
+end



More information about the flang-commits mailing list