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