Skip to content

Commit 305d05a

Browse files
authored
Merge pull request #1018 from flang-compiler/jpr-derived-type-lbs
Add hard todo for non default component lower bounds
2 parents 0c61733 + 87ecafe commit 305d05a

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

flang/lib/Lower/ConvertType.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,20 @@ struct TypeBuilder {
263263
return ty;
264264
}
265265

266+
/// Does \p component has non deferred lower bounds that are not compile time
267+
/// constant 1.
268+
static bool componentHasNonDefaultLowerBounds(
269+
const Fortran::semantics::Symbol &component) {
270+
if (const auto *objDetails =
271+
component.detailsIf<Fortran::semantics::ObjectEntityDetails>())
272+
for (const auto &bounds : objDetails->shape())
273+
if (auto lb = bounds.lbound().GetExplicit())
274+
if (auto constant = Fortran::evaluate::ToInt64(*lb))
275+
if (!constant || *constant != 1)
276+
return true;
277+
return false;
278+
}
279+
266280
mlir::Type genDerivedType(const Fortran::semantics::DerivedTypeSpec &tySpec) {
267281
std::vector<std::pair<std::string, mlir::Type>> ps;
268282
std::vector<std::pair<std::string, mlir::Type>> cs;
@@ -278,6 +292,11 @@ struct TypeBuilder {
278292
// (1) The data components.
279293
for (const auto &field :
280294
Fortran::semantics::OrderedComponentIterator(tySpec)) {
295+
// Lowering is assuming non deferred component lower bounds are always 1.
296+
// Catch any situations where this is not true for now.
297+
if (componentHasNonDefaultLowerBounds(field))
298+
TODO(converter.genLocation(field.name()),
299+
"lowering derived type components with non default lower bounds");
281300
auto ty = genSymbolType(field);
282301
// Do not add the parent component (component of the parents are
283302
// added and should be sufficient, the parent component would

0 commit comments

Comments
 (0)