[flang-commits] [flang] [flang] Silence spurious error (PR #104821)

via flang-commits flang-commits at lists.llvm.org
Mon Aug 19 10:56:00 PDT 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-flang-semantics

Author: Peter Klausler (klausler)

<details>
<summary>Changes</summary>

Don't complain about a local object with an impure final procedure in a pure subprogram when the local object is a named constant.

Fixes https://github.com/llvm/llvm-project/issues/104796.

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


2 Files Affected:

- (modified) flang/lib/Semantics/tools.cpp (+3-2) 
- (modified) flang/test/Semantics/declarations05.f90 (+1) 


``````````diff
diff --git a/flang/lib/Semantics/tools.cpp b/flang/lib/Semantics/tools.cpp
index 57d84bde60b43c..845183f2d9b253 100644
--- a/flang/lib/Semantics/tools.cpp
+++ b/flang/lib/Semantics/tools.cpp
@@ -1558,8 +1558,9 @@ bool IsAutomaticallyDestroyed(const Symbol &symbol) {
   return symbol.has<ObjectEntityDetails>() &&
       (symbol.owner().kind() == Scope::Kind::Subprogram ||
           symbol.owner().kind() == Scope::Kind::BlockConstruct) &&
-      (!IsDummy(symbol) || IsIntentOut(symbol)) && !IsPointer(symbol) &&
-      !IsSaved(symbol) && !FindCommonBlockContaining(symbol);
+      !IsNamedConstant(symbol) && (!IsDummy(symbol) || IsIntentOut(symbol)) &&
+      !IsPointer(symbol) && !IsSaved(symbol) &&
+      !FindCommonBlockContaining(symbol);
 }
 
 const std::optional<parser::Name> &MaybeGetNodeName(
diff --git a/flang/test/Semantics/declarations05.f90 b/flang/test/Semantics/declarations05.f90
index 5144f0b91ab9de..b6dab7aeea0bc8 100644
--- a/flang/test/Semantics/declarations05.f90
+++ b/flang/test/Semantics/declarations05.f90
@@ -29,6 +29,7 @@ pure subroutine test
     type(t1) x1
     !WARNING: 'x1a' of derived type 't1' does not have a FINAL subroutine for its rank (1)
     type(t1), allocatable :: x1a(:)
+    type(t1), parameter :: namedConst = t1() ! ok
     !ERROR: 'x2' may not be a local variable in a pure subprogram
     !BECAUSE: 'x2' has an impure FINAL procedure 'final'
     type(t2) x2

``````````

</details>


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


More information about the flang-commits mailing list