diff options
author | jeanPerier <jperier@nvidia.com> | 2023-09-18 14:59:56 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-09-18 14:59:56 +0200 |
commit | 99a54b839a441a6e9dd9106c5fd9e547cf1309e5 (patch) | |
tree | dcc32ec6c6f98bf2e8b09e66a8430da5fdfcc2b0 /flang/lib/Lower/ConvertType.cpp | |
parent | 4491f0b969c04c93e8db397d51c6986e9371a49b (diff) | |
download | llvm-99a54b839a441a6e9dd9106c5fd9e547cf1309e5.zip llvm-99a54b839a441a6e9dd9106c5fd9e547cf1309e5.tar.gz llvm-99a54b839a441a6e9dd9106c5fd9e547cf1309e5.tar.bz2 |
[flang] Lower PRIVATE component names safely (#66076)
It is possible for a derived type extending a type with private
components to define components with the same name as the private
components.
This was not properly handled by lowering where several fir.record type
component names could end-up being the same, leading to bad generated
code (only the first component was accessed via fir.field_index, leading
to bad generated code).
This patch handles the situation by adding the derived type mangled name
to private component.
Diffstat (limited to 'flang/lib/Lower/ConvertType.cpp')
-rw-r--r-- | flang/lib/Lower/ConvertType.cpp | 20 |
1 files changed, 11 insertions, 9 deletions
diff --git a/flang/lib/Lower/ConvertType.cpp b/flang/lib/Lower/ConvertType.cpp index e8179b4..bfddf9a 100644 --- a/flang/lib/Lower/ConvertType.cpp +++ b/flang/lib/Lower/ConvertType.cpp @@ -382,23 +382,25 @@ struct TypeBuilderImpl { // Gather the record type fields. // (1) The data components. - for (const auto &field : + for (const auto &component : Fortran::semantics::OrderedComponentIterator(tySpec)) { // Lowering is assuming non deferred component lower bounds are always 1. // Catch any situations where this is not true for now. if (!converter.getLoweringOptions().getLowerToHighLevelFIR() && - componentHasNonDefaultLowerBounds(field)) - TODO(converter.genLocation(field.name()), + componentHasNonDefaultLowerBounds(component)) + TODO(converter.genLocation(component.name()), "derived type components with non default lower bounds"); - if (IsProcedure(field)) - TODO(converter.genLocation(field.name()), "procedure components"); - mlir::Type ty = genSymbolType(field); + if (IsProcedure(component)) + TODO(converter.genLocation(component.name()), "procedure components"); + mlir::Type ty = genSymbolType(component); // Do not add the parent component (component of the parents are // added and should be sufficient, the parent component would - // duplicate the fields). - if (field.test(Fortran::semantics::Symbol::Flag::ParentComp)) + // duplicate the fields). Note that genSymbolType must be called above on + // it so that the dispatch table for the parent type still gets emitted + // as needed. + if (component.test(Fortran::semantics::Symbol::Flag::ParentComp)) continue; - cs.emplace_back(field.name().ToString(), ty); + cs.emplace_back(converter.getRecordTypeFieldName(component), ty); } // (2) The LEN type parameters. |