[flang-commits] [flang] [flang] Silence an inappropriate warning (PR #104685)

Peter Klausler via flang-commits flang-commits at lists.llvm.org
Sat Aug 17 13:53:38 PDT 2024


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

A bare ALLOCATE statement with no SOURCE= rightly earns a warning about an undefined function result, if that result is an allocatable that appears in the ALLOCATE.  But in the case of a pointer, where the warning should care more about the pointer's association status than the value of its target, a bare ALLOCATE should suffice to silence the warning.

>From 5600d6aaf6c0f31307cb2569b9db429d3bf1b9bc Mon Sep 17 00:00:00 2001
From: Peter Klausler <pklausler at nvidia.com>
Date: Sat, 17 Aug 2024 13:49:55 -0700
Subject: [PATCH] [flang] Silence an inappropriate warning

A bare ALLOCATE statement with no SOURCE= rightly earns a warning
about an undefined function result, if that result is an allocatable
that appears in the ALLOCATE.  But in the case of a pointer, where
the warning should care more about the pointer's association status
than the value of its target, a bare ALLOCATE should suffice to
silence the warning.
---
 flang/lib/Semantics/definable.cpp       | 2 +-
 flang/test/Semantics/undef-result01.f90 | 5 +++++
 2 files changed, 6 insertions(+), 1 deletion(-)

diff --git a/flang/lib/Semantics/definable.cpp b/flang/lib/Semantics/definable.cpp
index 62fed63df4475c..5c41376d2a42bf 100644
--- a/flang/lib/Semantics/definable.cpp
+++ b/flang/lib/Semantics/definable.cpp
@@ -127,7 +127,7 @@ static std::optional<parser::Message> WhyNotDefinableBase(parser::CharBlock at,
       (!IsPointer(ultimate) || (isWholeSymbol && isPointerDefinition))) {
     return BlameSymbol(
         at, "'%s' is an INTENT(IN) dummy argument"_en_US, original);
-  } else if (acceptAllocatable &&
+  } else if (acceptAllocatable && IsAllocatable(ultimate) &&
       !flags.test(DefinabilityFlag::SourcedAllocation)) {
     // allocating a function result doesn't count as a def'n
     // unless there's SOURCE=
diff --git a/flang/test/Semantics/undef-result01.f90 b/flang/test/Semantics/undef-result01.f90
index dd73f9c76df0a5..bf6af11a8d7b92 100644
--- a/flang/test/Semantics/undef-result01.f90
+++ b/flang/test/Semantics/undef-result01.f90
@@ -44,6 +44,11 @@ function basicAlloc()
   allocate(basicAlloc)
 end
 
+function allocPtr()
+  real, pointer :: allocPtr
+  allocate(allocPtr) ! good enough for pointer
+end
+
 function sourcedAlloc()
   real, allocatable :: sourcedAlloc
   allocate(sourcedAlloc, source=0.)



More information about the flang-commits mailing list