diff --git a/flang/lib/Optimizer/Builder/IntrinsicCall.cpp b/flang/lib/Optimizer/Builder/IntrinsicCall.cpp --- a/flang/lib/Optimizer/Builder/IntrinsicCall.cpp +++ b/flang/lib/Optimizer/Builder/IntrinsicCall.cpp @@ -4035,10 +4035,18 @@ mlir::Value fsourceCast = fsource; if (fir::isPolymorphicType(tsource.getType()) && !fir::isPolymorphicType(fsource.getType())) { - tsourceCast = builder.createConvert(loc, fsource.getType(), tsource); + tsourceCast = builder.create(loc, fsource.getType(), tsource, + /*shape*/ mlir::Value{}, + /*slice=*/mlir::Value{}); + + // builder.createConvert(loc, fsource.getType(), tsource); } else if (!fir::isPolymorphicType(tsource.getType()) && fir::isPolymorphicType(fsource.getType())) { - fsourceCast = builder.createConvert(loc, tsource.getType(), fsource); + fsourceCast = builder.create(loc, tsource.getType(), fsource, + /*shape*/ mlir::Value{}, + /*slice=*/mlir::Value{}); + + // fsourceCast = builder.createConvert(loc, tsource.getType(), fsource); } else { // FSOURCE and TSOURCE are not polymorphic. // FSOURCE has the same type as TSOURCE, but they may not have the same MLIR diff --git a/flang/test/Lower/polymorphic-temp.f90 b/flang/test/Lower/polymorphic-temp.f90 --- a/flang/test/Lower/polymorphic-temp.f90 +++ b/flang/test/Lower/polymorphic-temp.f90 @@ -222,7 +222,7 @@ ! CHECK: %[[LOAD_I:.*]] = fir.load %[[I]] : !fir.ref ! CHECK: %[[C1:.*]] = arith.constant 1 : i32 ! CHECK: %[[CMPI:.*]] = arith.cmpi eq, %[[LOAD_I]], %[[C1]] : i32 -! CHECK: %[[A_CONV:.*]] = fir.convert %[[LOAD_A]] : (!fir.class>>) -> !fir.box>> -! CHECK: %{{.*}} = arith.select %[[CMPI]], %[[A_CONV]], %[[LOAD_B]] : !fir.box>> +! CHECK: %[[A_REBOX:.*]] = fir.rebox %[[LOAD_A]] : (!fir.class>>) -> !fir.box>> +! CHECK: %{{.*}} = arith.select %[[CMPI]], %[[A_REBOX]], %[[LOAD_B]] : !fir.box>> end module