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

via flang-commits flang-commits at lists.llvm.org
Sat Aug 17 13:54:09 PDT 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-flang-semantics

Author: Peter Klausler (klausler)

<details>
<summary>Changes</summary>

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.

---
Full diff: https://github.com/llvm/llvm-project/pull/104685.diff


2 Files Affected:

- (modified) flang/lib/Semantics/definable.cpp (+1-1) 
- (modified) flang/test/Semantics/undef-result01.f90 (+5) 


``````````diff
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.)

``````````

</details>


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


More information about the flang-commits mailing list