@@ -609,11 +609,22 @@ static void genNamelistIO(Fortran::lower::AbstractConverter &converter,
609
609
ok = builder.create <fir::CallOp>(loc, funcOp, args).getResult (0 );
610
610
}
611
611
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
+
612
623
// / Get the output function to call for a value of the given type.
613
624
static mlir::func::FuncOp getOutputFunc (mlir::Location loc,
614
625
fir::FirOpBuilder &builder,
615
626
mlir::Type type, bool isFormatted) {
616
- if (mlir::isa<fir::RecordType>( fir::unwrapPassByRefType ( type) ))
627
+ if (containsDerivedType ( type))
617
628
return fir::runtime::getIORuntimeFunc<mkIOKey (OutputDerivedType)>(loc,
618
629
builder);
619
630
if (!isFormatted)
@@ -710,7 +721,7 @@ static void genOutputItemList(
710
721
if (mlir::isa<fir::BoxType>(argType)) {
711
722
mlir::Value box = fir::getBase (converter.genExprBox (loc, *expr, stmtCtx));
712
723
outputFuncArgs.push_back (builder.createConvert (loc, argType, box));
713
- if (mlir::isa<fir::RecordType>( fir::unwrapPassByRefType ( itemTy) ))
724
+ if (containsDerivedType ( itemTy))
714
725
outputFuncArgs.push_back (getNonTbpDefinedIoTableAddr (converter));
715
726
} else if (helper.isCharacterScalar (itemTy)) {
716
727
fir::ExtendedValue exv = converter.genExprAddr (loc, expr, stmtCtx);
@@ -745,7 +756,7 @@ static void genOutputItemList(
745
756
static mlir::func::FuncOp getInputFunc (mlir::Location loc,
746
757
fir::FirOpBuilder &builder,
747
758
mlir::Type type, bool isFormatted) {
748
- if (mlir::isa<fir::RecordType>( fir::unwrapPassByRefType ( type) ))
759
+ if (containsDerivedType ( type))
749
760
return fir::runtime::getIORuntimeFunc<mkIOKey (InputDerivedType)>(loc,
750
761
builder);
751
762
if (!isFormatted)
@@ -817,7 +828,7 @@ createIoRuntimeCallForItem(Fortran::lower::AbstractConverter &converter,
817
828
auto boxTy = mlir::dyn_cast<fir::BaseBoxType>(box.getType ());
818
829
assert (boxTy && " must be previously emboxed" );
819
830
inputFuncArgs.push_back (builder.createConvert (loc, argType, box));
820
- if (mlir::isa<fir::RecordType>( fir::unwrapPassByRefType ( boxTy) ))
831
+ if (containsDerivedType ( boxTy))
821
832
inputFuncArgs.push_back (getNonTbpDefinedIoTableAddr (converter));
822
833
} else {
823
834
mlir::Value itemAddr = fir::getBase (item);
0 commit comments