diff --git a/flang/include/flang/Semantics/runtime-type-info.h b/flang/include/flang/Semantics/runtime-type-info.h --- a/flang/include/flang/Semantics/runtime-type-info.h +++ b/flang/include/flang/Semantics/runtime-type-info.h @@ -14,6 +14,7 @@ #ifndef FORTRAN_SEMANTICS_RUNTIME_TYPE_INFO_H_ #define FORTRAN_SEMANTICS_RUNTIME_TYPE_INFO_H_ +#include "flang/Common/reference.h" #include #include #include @@ -27,6 +28,9 @@ class SemanticsContext; class Symbol; +using SymbolRef = common::Reference; +using SymbolVector = std::vector; + struct RuntimeDerivedTypeTables { Scope *schemata{nullptr}; std::set names; @@ -38,7 +42,7 @@ /// to describe other derived types at runtime in flang descriptor. constexpr char typeInfoBuiltinModule[]{"__fortran_type_info"}; -std::vector CollectBindings(const Scope &dtScope); +SymbolVector CollectBindings(const Scope &dtScope); } // namespace Fortran::semantics #endif // FORTRAN_SEMANTICS_RUNTIME_TYPE_INFO_H_ 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 @@ -223,21 +223,21 @@ parent ? Fortran::lower::mangle::mangleName(*parent) : ""); auto insertPt = builder.saveInsertionPoint(); - std::vector bindings = + Fortran::semantics::SymbolVector bindings = Fortran::semantics::CollectBindings(*info.typeSpec->scope()); if (!bindings.empty()) builder.createBlock(&dt.getRegion()); - for (const Fortran::semantics::Symbol *binding : bindings) { + for (const Fortran::semantics::SymbolRef binding : bindings) { const auto *details = - binding->detailsIf(); + binding.get().detailsIf(); std::string bindingName = Fortran::lower::mangle::mangleName(details->symbol()); builder.create( info.loc, mlir::StringAttr::get(builder.getContext(), - binding->name().ToString()), + binding.get().name().ToString()), mlir::SymbolRefAttr::get(builder.getContext(), bindingName)); } if (!bindings.empty()) diff --git a/flang/lib/Semantics/runtime-type-info.cpp b/flang/lib/Semantics/runtime-type-info.cpp --- a/flang/lib/Semantics/runtime-type-info.cpp +++ b/flang/lib/Semantics/runtime-type-info.cpp @@ -940,8 +940,8 @@ return StructureExpr(PackageIntValue(genre, n)); } -std::vector CollectBindings(const Scope &dtScope) { - std::vector result; +SymbolVector CollectBindings(const Scope &dtScope) { + SymbolVector result; std::map localBindings; // Collect local bindings for (auto pair : dtScope) { @@ -957,14 +957,14 @@ const Symbol &symbol{**iter}; auto overridden{localBindings.find(symbol.name())}; if (overridden != localBindings.end()) { - *iter = overridden->second; + *iter = *overridden->second; localBindings.erase(overridden); } } } // Add remaining (non-overriding) local bindings in name order to the result for (auto pair : localBindings) { - result.push_back(pair.second); + result.push_back(*pair.second); } return result; } @@ -972,13 +972,13 @@ std::vector RuntimeTableBuilder::DescribeBindings(const Scope &dtScope, Scope &scope) { std::vector result; - for (const Symbol *symbol : CollectBindings(dtScope)) { + for (const SymbolRef ref : CollectBindings(dtScope)) { evaluate::StructureConstructorValues values; AddValue(values, bindingSchema_, "proc"s, SomeExpr{evaluate::ProcedureDesignator{ - symbol->get().symbol()}}); + ref.get().get().symbol()}}); AddValue(values, bindingSchema_, "name"s, - SaveNameAsPointerTarget(scope, symbol->name().ToString())); + SaveNameAsPointerTarget(scope, ref.get().name().ToString())); result.emplace_back(DEREF(bindingSchema_.AsDerived()), std::move(values)); } return result;