[flang-commits] [flang] Get the BoxType from the RHS instead of LHS for polymorphic pointer assignment inside FORALL. (PR #164279)
Daniel Chen via flang-commits
flang-commits at lists.llvm.org
Tue Oct 21 12:38:20 PDT 2025
================
@@ -4730,13 +4730,14 @@ class FirConverter : public Fortran::lower::AbstractConverter {
if (Fortran::evaluate::UnwrapExpr<Fortran::evaluate::NullPointer>(
assign.rhs))
return fir::factory::createUnallocatedBox(*builder, loc, lhsBoxType, {});
- hlfir::Entity rhs = Fortran::lower::convertExprToHLFIR(
- loc, *this, assign.rhs, localSymbols, rhsContext);
+ hlfir::Entity rhs{fir::getBase(genExprBox(loc, assign.rhs, rhsContext))};
+ auto rhsBoxType =
+ llvm::cast<fir::BaseBoxType>(fir::unwrapRefType(rhs.getType()));
----------------
DanielCChen wrote:
@jeanPerier
Thanks for the quick review and the suggesion!
I tried your suggestion, but got core dump as
```
flang: /scratch/cdchen/FLANG/llvm-project/llvm/include/llvm/Support/Casting.h:560: decltype(auto) llvm::cast(const From &) [To = fir::BaseBoxType, From = mlir::Type]: Assertion `isa<To>(Val) && "cast<Ty>() argument of incompatible type!"' failed.
```
The expected `rhsBoxType` should be `!fir.box<!fir.char<1>>`, which is what the the current patch returns.
However, with `convertExprToHLFIR`, I got `!fir.ref<!fir.char<1>>`.
The code `fir::getBase(genExprBox(loc, assign.rhs, rhsContext))` is also used by the exact same pointer assignment inside a DO loop (in comparison to FORALL).
https://github.com/llvm/llvm-project/pull/164279
More information about the flang-commits
mailing list