[flang-commits] [flang] [flang] Retrieve shape from selector when generating assoc sym type (PR #137117)

via flang-commits flang-commits at lists.llvm.org
Mon May 19 05:42:55 PDT 2025


================
@@ -279,6 +279,23 @@ struct TypeBuilderImpl {
     bool isPolymorphic = (Fortran::semantics::IsPolymorphic(symbol) ||
                           Fortran::semantics::IsUnlimitedPolymorphic(symbol)) &&
                          !Fortran::semantics::IsAssumedType(symbol);
+    if (const auto *assocDetails =
----------------
jeanPerier wrote:

Sorry for the very late reply, I missed the mails, do not hesitate to call me back for review when I am late to reply. Thanks for the reply, I can understand why Symbol::GetShape returns nothing given there is no textual shape-spec in the source for selectors.

However, `evaluate::GetShape` that is called here in lowering is supposed to work directly with AssocEntityDetails (I see some handling for it [here](https://github.com/llvm/llvm-project/blob/e8a307498d678970e0be8cd7718ba0779d5ee307/flang/lib/Evaluate/shape.cpp#L821C16-L828C20)).

So to avoid duplicating code, maybe the best is just to simplify the code to do:

```
auto shapeExpr= Fortran::evaluate::GetShape(....);
if (shapeExpr && !shapeExpr.empty())
  // Statically ranked array.
  fir::SequenceType::Shape shape;
  translateShape(shape, std::move(*shapeExpr));
  ty = ...
} else if (!shapeExpr ) {
  // Assumed-rank.
  ty = fir::SequenceType::get([shape](fir::SequenceType::Shape{}, ty);
}
```


https://github.com/llvm/llvm-project/pull/137117


More information about the flang-commits mailing list