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

via flang-commits flang-commits at lists.llvm.org
Tue Aug 20 12:04:01 PDT 2024


Author: Peter Klausler
Date: 2024-08-20T12:03:57-07:00
New Revision: f0590177b28a3940b9afdf2f65eae054eeb49eed

URL: https://github.com/llvm/llvm-project/commit/f0590177b28a3940b9afdf2f65eae054eeb49eed
DIFF: https://github.com/llvm/llvm-project/commit/f0590177b28a3940b9afdf2f65eae054eeb49eed.diff

LOG: [flang] Silence an inappropriate warning (#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.

Added: 
    

Modified: 
    flang/lib/Semantics/definable.cpp
    flang/test/Semantics/undef-result01.f90

Removed: 
    


################################################################################
diff  --git a/flang/lib/Semantics/definable.cpp b/flang/lib/Semantics/definable.cpp
index 62fed63df4475..5c41376d2a42b 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 dd73f9c76df0a..bf6af11a8d7b9 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