@@ -748,7 +748,8 @@ class FirConverter : public Fortran::lower::AbstractConverter {
748748
749749 void copyVar (mlir::Location loc, mlir::Value dst,
750750 mlir::Value src) override final {
751- copyVarHLFIR (loc, dst, src);
751+ copyVarHLFIR (loc, Fortran::lower::SymbolBox::Intrinsic{dst},
752+ Fortran::lower::SymbolBox::Intrinsic{src});
752753 }
753754
754755 void copyHostAssociateVar (
@@ -1009,10 +1010,7 @@ class FirConverter : public Fortran::lower::AbstractConverter {
10091010 // `omp.private`'s `alloc` block. If this is the case, we return this
10101011 // `SymbolBox::Intrinsic` value.
10111012 if (Fortran::lower::SymbolBox v = symMap->lookupSymbol (sym))
1012- return v.match (
1013- [&](const Fortran::lower::SymbolBox::Intrinsic &)
1014- -> Fortran::lower::SymbolBox { return v; },
1015- [](const auto &) -> Fortran::lower::SymbolBox { return {}; });
1013+ return v;
10161014
10171015 return {};
10181016 }
@@ -1060,15 +1058,16 @@ class FirConverter : public Fortran::lower::AbstractConverter {
10601058 const Fortran::lower::SymbolBox &rhs_sb) {
10611059 mlir::Location loc = genLocation (sym.name ());
10621060 if (lowerToHighLevelFIR ())
1063- copyVarHLFIR (loc, lhs_sb. getAddr () , rhs_sb. getAddr () );
1061+ copyVarHLFIR (loc, lhs_sb, rhs_sb);
10641062 else
10651063 copyVarFIR (loc, sym, lhs_sb, rhs_sb);
10661064 }
10671065
1068- void copyVarHLFIR (mlir::Location loc, mlir::Value dst, mlir::Value src) {
1066+ void copyVarHLFIR (mlir::Location loc, Fortran::lower::SymbolBox dst,
1067+ Fortran::lower::SymbolBox src) {
10691068 assert (lowerToHighLevelFIR ());
1070- hlfir::Entity lhs{dst};
1071- hlfir::Entity rhs{src};
1069+ hlfir::Entity lhs{dst. getAddr () };
1070+ hlfir::Entity rhs{src. getAddr () };
10721071 // Temporary_lhs is set to true in hlfir.assign below to avoid user
10731072 // assignment to be used and finalization to be called on the LHS.
10741073 // This may or may not be correct but mimics the current behaviour
@@ -1082,7 +1081,22 @@ class FirConverter : public Fortran::lower::AbstractConverter {
10821081 /* keepLhsLengthInAllocatableAssignment=*/ false ,
10831082 /* temporary_lhs=*/ true );
10841083 };
1085- if (lhs.isAllocatable ()) {
1084+
1085+ bool isBoxAllocatable = dst.match (
1086+ [](const fir::MutableBoxValue &box) { return box.isAllocatable (); },
1087+ [](const fir::FortranVariableOpInterface &box) {
1088+ return fir::FortranVariableOpInterface (box).isAllocatable ();
1089+ },
1090+ [](const auto &box) { return false ; });
1091+
1092+ bool isBoxPointer = dst.match (
1093+ [](const fir::MutableBoxValue &box) { return box.isPointer (); },
1094+ [](const fir::FortranVariableOpInterface &box) {
1095+ return fir::FortranVariableOpInterface (box).isPointer ();
1096+ },
1097+ [](const auto &box) { return false ; });
1098+
1099+ if (isBoxAllocatable) {
10861100 // Deep copy allocatable if it is allocated.
10871101 // Note that when allocated, the RHS is already allocated with the LHS
10881102 // shape for copy on entry in createHostAssociateVarClone.
@@ -1097,7 +1111,7 @@ class FirConverter : public Fortran::lower::AbstractConverter {
10971111 copyData (lhs, rhs);
10981112 })
10991113 .end ();
1100- } else if (lhs. isPointer () ) {
1114+ } else if (isBoxPointer ) {
11011115 // Set LHS target to the target of RHS (do not copy the RHS
11021116 // target data into the LHS target storage).
11031117 auto loadVal = builder->create <fir::LoadOp>(loc, rhs);
0 commit comments