[flang-commits] [flang] [flang] Use the namelist item descriptor if it is local polymorphic entity. (PR #162701)
Daniel Chen via flang-commits
flang-commits at lists.llvm.org
Thu Oct 9 11:44:48 PDT 2025
DanielCChen wrote:
> Thanks for working on this!
>
> ```
> ! CHECK: %[[V_14:[0-9]+]] = fir.convert %[[V_13]] : (!fir.class<!fir.heap<!fir.type<_QMmTbase{r1:f32}>>>) -> !fir.ref<!fir.box<none>>
> ```
>
> That is a very suspicious cast that only happens to work because of the current fir.box codegen. I'll need to check why this is allowed.
>
> I would rather not rely on this. The fix I think is to update the: `fir::BoxType boxType = fir::BoxType::get(fir::PointerType::get(type));` to something like `fir::BaseBoxType boxType = mlir::isa<fir::ClassType>(type) ? fir::ClassType::get(fir::PointerType::get(type)) : fir::BoxType::get(fir::PointerType::get(type));` (this is not correct C++, just to illustrate).
>
> The point is that the created temporary pointer should be a polymorphic pointer so that is correctly associated.
Thanks for the quick review!
The suspicious cast is also happening for the non-namelist I/O.
If I changed the write statement to `write(10, *) b1`, I also got
```
%8 = fir.load %4 : !fir.ref<!fir.class<!fir.heap<!fir.type<_QMmTbase{r1:f32}>>>>
%9 = fir.convert %8 : (!fir.class<!fir.heap<!fir.type<_QMmTbase{r1:f32}>>>) -> !fir.box<none>
```
https://github.com/llvm/llvm-project/pull/162701
More information about the flang-commits
mailing list