@@ -5509,10 +5509,34 @@ class FirConverter : public Fortran::lower::AbstractConverter {
5509
5509
void genFIR (const Fortran::parser::AssignStmt &stmt) {
5510
5510
const Fortran::semantics::Symbol &symbol =
5511
5511
*std::get<Fortran::parser::Name>(stmt.t ).symbol ;
5512
+
5512
5513
mlir::Location loc = toLocation ();
5514
+ mlir::Type symbolType = genType (symbol);
5515
+ mlir::Value addr = getSymbolAddress (symbol);
5516
+
5517
+ // Handle the case where the assigned variable is declared as a pointer
5518
+ if (auto eleTy = fir::dyn_cast_ptrOrBoxEleTy (symbolType)) {
5519
+ if (auto ptrType = mlir::dyn_cast<fir::PointerType>(eleTy)) {
5520
+ symbolType = ptrType.getEleTy ();
5521
+ } else {
5522
+ symbolType = eleTy;
5523
+ }
5524
+ } else if (auto ptrType = mlir::dyn_cast<fir::PointerType>(symbolType)) {
5525
+ symbolType = ptrType.getEleTy ();
5526
+ }
5527
+
5513
5528
mlir::Value labelValue = builder->createIntegerConstant (
5514
- loc, genType (symbol), std::get<Fortran::parser::Label>(stmt.t ));
5515
- builder->create <fir::StoreOp>(loc, labelValue, getSymbolAddress (symbol));
5529
+ loc, symbolType, std::get<Fortran::parser::Label>(stmt.t ));
5530
+
5531
+ // If the address points to a boxed pointer, we need to dereference it
5532
+ if (auto refType = mlir::dyn_cast<fir::ReferenceType>(addr.getType ())) {
5533
+ if (auto boxType = mlir::dyn_cast<fir::BoxType>(refType.getEleTy ())) {
5534
+ mlir::Value boxValue = builder->create <fir::LoadOp>(loc, addr);
5535
+ addr = builder->create <fir::BoxAddrOp>(loc, boxValue);
5536
+ }
5537
+ }
5538
+
5539
+ builder->create <fir::StoreOp>(loc, labelValue, addr);
5516
5540
}
5517
5541
5518
5542
void genFIR (const Fortran::parser::FormatStmt &) {
0 commit comments