[flang-commits] [flang] [Flang] Fix ASSIGN statement (PR #149941)
Tom Eccles via flang-commits
flang-commits at lists.llvm.org
Wed Jul 23 01:20:49 PDT 2025
================
@@ -5506,10 +5506,34 @@ class FirConverter : public Fortran::lower::AbstractConverter {
void genFIR(const Fortran::parser::AssignStmt &stmt) {
const Fortran::semantics::Symbol &symbol =
*std::get<Fortran::parser::Name>(stmt.t).symbol;
+
mlir::Location loc = toLocation();
+ mlir::Type symbolType = genType(symbol);
+ mlir::Value addr = getSymbolAddress(symbol);
+
+ // Handle the case where the assigned variable is declared as a pointer
+ if (auto eleTy = fir::dyn_cast_ptrOrBoxEleTy(symbolType)) {
+ if (auto ptrType = mlir::dyn_cast<fir::PointerType>(eleTy)) {
+ symbolType = ptrType.getEleTy();
+ } else {
+ symbolType = eleTy;
+ }
+ } else if (auto ptrType = mlir::dyn_cast<fir::PointerType>(symbolType)) {
+ symbolType = ptrType.getEleTy();
+ }
+
mlir::Value labelValue = builder->createIntegerConstant(
- loc, genType(symbol), std::get<Fortran::parser::Label>(stmt.t));
- builder->create<fir::StoreOp>(loc, labelValue, getSymbolAddress(symbol));
+ loc, symbolType, std::get<Fortran::parser::Label>(stmt.t));
+
+ // If the address points to a boxed pointer, we need to dereference it
+ if (auto refType = mlir::dyn_cast<fir::ReferenceType>(addr.getType())) {
+ if (auto boxType = mlir::dyn_cast<fir::BoxType>(refType.getEleTy())) {
+ mlir::Value boxValue = builder->create<fir::LoadOp>(loc, addr);
+ addr = builder->create<fir::BoxAddrOp>(loc, boxValue);
----------------
tblah wrote:
FYI: this syntax will be deprecated in LLVM 22. `fir::BoxAddrOp::create(bulider, loc, boxValue)` is the new style. But maybe don't do that here so that the patch is backportable to 21
https://github.com/llvm/llvm-project/pull/149941
More information about the flang-commits
mailing list