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

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


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

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.

>From 1211ee57ef617d10ce0472112246fb24800215b4 Mon Sep 17 00:00:00 2001
From: Peter Klausler <pklausler at nvidia.com>
Date: Wed, 15 May 2024 08:30:31 -0700
Subject: [PATCH] [flang] Prevent crash from unfoldable TRANSFER()

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.
---
 flang/lib/Evaluate/fold.cpp | 1 +
 1 file changed, 1 insertion(+)

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])};



More information about the flang-commits mailing list