[flang-commits] [flang] [flang][hlfir] address char_convert issues as mentioned in #64315 (PR #67570)

via flang-commits flang-commits at lists.llvm.org
Wed Oct 4 00:36:40 PDT 2023


================
@@ -1435,8 +1434,12 @@ struct UnaryOp<
       // allocate space on the stack for toBuffer
       auto dest = builder.create<fir::AllocaOp>(loc, toTy,
                                                 mlir::ValueRange{bufferSize});
-      builder.create<fir::CharConvertOp>(loc, lhs.getFirBase(), origBufferSize,
-                                         dest);
+      auto src = hlfir::convertToAddress(loc, builder, lhs,
+                                         lhs.getFortranElementType());
+      builder.create<fir::CharConvertOp>(loc, src.first.getCharBox()->getAddr(),
+                                         origBufferSize, dest);
+      if (src.second.has_value())
+        src.second.value();
----------------
jeanPerier wrote:

Are you sure this is calling the cleanup? I would actually expect `src.second.value()()` or `(*src.second)()` here.

Can you ensure there is an hlfir.end_associate created after the fir.char_convert for the following example:

```
subroutine charconvert3(c, c4)
  character(kind=1, len=*) :: c
  character(kind=4, len=*) :: c4
  c4 = c // c
end subroutine
```

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


More information about the flang-commits mailing list