diff --git a/flang/lib/Lower/Bridge.cpp b/flang/lib/Lower/Bridge.cpp --- a/flang/lib/Lower/Bridge.cpp +++ b/flang/lib/Lower/Bridge.cpp @@ -2859,20 +2859,21 @@ // Assignment to/from polymorphic entities are done with the // runtime. - if (lhsType->IsPolymorphic() || - lhsType->IsUnlimitedPolymorphic() || - rhsType->IsPolymorphic() || - rhsType->IsUnlimitedPolymorphic()) { - mlir::Value lhs; - if (Fortran::lower::isWholeAllocatable(assign.lhs)) - lhs = genExprMutableBox(loc, assign.lhs).getAddr(); - else - lhs = fir::getBase(genExprBox(loc, assign.lhs, stmtCtx)); - mlir::Value rhs = - fir::getBase(genExprBox(loc, assign.rhs, stmtCtx)); - fir::runtime::genAssign(*builder, loc, lhs, rhs); - return; - } + if (rhsType) // Eliminate BOZ on rhs + if (lhsType->IsPolymorphic() || + lhsType->IsUnlimitedPolymorphic() || + rhsType->IsPolymorphic() || + rhsType->IsUnlimitedPolymorphic()) { + mlir::Value lhs; + if (Fortran::lower::isWholeAllocatable(assign.lhs)) + lhs = genExprMutableBox(loc, assign.lhs).getAddr(); + else + lhs = fir::getBase(genExprBox(loc, assign.lhs, stmtCtx)); + mlir::Value rhs = + fir::getBase(genExprBox(loc, assign.rhs, stmtCtx)); + fir::runtime::genAssign(*builder, loc, lhs, rhs); + return; + } // Note: No ad-hoc handling for pointers is required here. The // target will be assigned as per 2018 10.2.1.3 p2. genExprAddr