diff --git a/flang/lib/Optimizer/Dialect/FIRType.cpp b/flang/lib/Optimizer/Dialect/FIRType.cpp --- a/flang/lib/Optimizer/Dialect/FIRType.cpp +++ b/flang/lib/Optimizer/Dialect/FIRType.cpp @@ -482,7 +482,8 @@ std::string getTypeAsString(mlir::Type ty, const fir::KindMapping &kindMap, llvm::StringRef prefix) { - std::stringstream name; + std::string buf; + llvm::raw_string_ostream name{buf}; name << prefix.str(); if (!prefix.empty()) name << "_"; @@ -535,8 +536,10 @@ } else if (auto boxTy = mlir::dyn_cast_or_null(ty)) { name << "box_"; ty = boxTy.getEleTy(); + } else if (auto recTy = mlir::dyn_cast_or_null(ty)) { + name << "rec_" << recTy.getName(); + break; } else { - // TODO: add support for RecordType llvm::report_fatal_error("unsupported type"); } } diff --git a/flang/unittests/Optimizer/FIRTypesTest.cpp b/flang/unittests/Optimizer/FIRTypesTest.cpp --- a/flang/unittests/Optimizer/FIRTypesTest.cpp +++ b/flang/unittests/Optimizer/FIRTypesTest.cpp @@ -299,4 +299,9 @@ EXPECT_EQ("class_none", fir::getTypeAsString( fir::ClassType::get(mlir::NoneType::get(&context)), *kindMap)); + auto derivedTy = fir::RecordType::get(&context, "derived"); + llvm::SmallVector> components; + components.emplace_back("p1", mlir::IntegerType::get(&context, 64)); + derivedTy.finalize({}, components); + EXPECT_EQ("rec_derived", fir::getTypeAsString(derivedTy, *kindMap)); }