@@ -609,11 +609,22 @@ static void genNamelistIO(Fortran::lower::AbstractConverter &converter,
609609 ok = builder.create <fir::CallOp>(loc, funcOp, args).getResult (0 );
610610}
611611
612+ // / Is \p type a derived type or an array of derived type?
613+ static bool containsDerivedType (mlir::Type type) {
614+ mlir::Type argTy = fir::unwrapPassByRefType (fir::unwrapRefType (type));
615+ if (mlir::isa<fir::RecordType>(argTy))
616+ return true ;
617+ if (auto seqTy = mlir::dyn_cast<fir::SequenceType>(argTy))
618+ if (mlir::isa<fir::RecordType>(seqTy.getEleTy ()))
619+ return true ;
620+ return false ;
621+ }
622+
612623// / Get the output function to call for a value of the given type.
613624static mlir::func::FuncOp getOutputFunc (mlir::Location loc,
614625 fir::FirOpBuilder &builder,
615626 mlir::Type type, bool isFormatted) {
616- if (mlir::isa<fir::RecordType>( fir::unwrapPassByRefType ( type) ))
627+ if (containsDerivedType ( type))
617628 return fir::runtime::getIORuntimeFunc<mkIOKey (OutputDerivedType)>(loc,
618629 builder);
619630 if (!isFormatted)
@@ -710,7 +721,7 @@ static void genOutputItemList(
710721 if (mlir::isa<fir::BoxType>(argType)) {
711722 mlir::Value box = fir::getBase (converter.genExprBox (loc, *expr, stmtCtx));
712723 outputFuncArgs.push_back (builder.createConvert (loc, argType, box));
713- if (mlir::isa<fir::RecordType>( fir::unwrapPassByRefType ( itemTy) ))
724+ if (containsDerivedType ( itemTy))
714725 outputFuncArgs.push_back (getNonTbpDefinedIoTableAddr (converter));
715726 } else if (helper.isCharacterScalar (itemTy)) {
716727 fir::ExtendedValue exv = converter.genExprAddr (loc, expr, stmtCtx);
@@ -745,7 +756,7 @@ static void genOutputItemList(
745756static mlir::func::FuncOp getInputFunc (mlir::Location loc,
746757 fir::FirOpBuilder &builder,
747758 mlir::Type type, bool isFormatted) {
748- if (mlir::isa<fir::RecordType>( fir::unwrapPassByRefType ( type) ))
759+ if (containsDerivedType ( type))
749760 return fir::runtime::getIORuntimeFunc<mkIOKey (InputDerivedType)>(loc,
750761 builder);
751762 if (!isFormatted)
@@ -817,7 +828,7 @@ createIoRuntimeCallForItem(Fortran::lower::AbstractConverter &converter,
817828 auto boxTy = mlir::dyn_cast<fir::BaseBoxType>(box.getType ());
818829 assert (boxTy && " must be previously emboxed" );
819830 inputFuncArgs.push_back (builder.createConvert (loc, argType, box));
820- if (mlir::isa<fir::RecordType>( fir::unwrapPassByRefType ( boxTy) ))
831+ if (containsDerivedType ( boxTy))
821832 inputFuncArgs.push_back (getNonTbpDefinedIoTableAddr (converter));
822833 } else {
823834 mlir::Value itemAddr = fir::getBase (item);
0 commit comments