[flang-commits] [flang] [flang] Prevent crash from unfoldable TRANSFER() (PR #92282)

via flang-commits flang-commits at lists.llvm.org
Wed May 15 08:33:44 PDT 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-flang-semantics

Author: Peter Klausler (klausler)

<details>
<summary>Changes</summary>

When the MOLD= argument's type is polymorphic, the type of the result cannot be known at compilation time, so the call cannot be folded even when the SOURCE= is constant.

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

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


1 Files Affected:

- (modified) flang/lib/Evaluate/fold.cpp (+1) 


``````````diff
diff --git a/flang/lib/Evaluate/fold.cpp b/flang/lib/Evaluate/fold.cpp
index ed88295819980..cf6262d9a7c65 100644
--- a/flang/lib/Evaluate/fold.cpp
+++ b/flang/lib/Evaluate/fold.cpp
@@ -272,6 +272,7 @@ std::optional<Expr<SomeType>> FoldTransfer(
     }
   }
   if (sourceBytes && IsActuallyConstant(*source) && moldType && extents &&
+      !moldType->IsPolymorphic() &&
       (moldLength || moldType->category() != TypeCategory::Character)) {
     std::size_t elements{
         extents->empty() ? 1 : static_cast<std::size_t>((*extents)[0])};

``````````

</details>


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


More information about the flang-commits mailing list