aboutsummaryrefslogtreecommitdiff
path: root/flang/lib/Lower/ConvertType.cpp
diff options
context:
space:
mode:
authorJean Perier <jperier@nvidia.com>2023-02-28 15:15:29 +0100
committerJean Perier <jperier@nvidia.com>2023-02-28 15:15:46 +0100
commitd8d91b2a25db8920c44a3dea36fc0eeff93bdfa0 (patch)
tree88a31cf52a5c6850b065a0ef7f6ac4961884f7f3 /flang/lib/Lower/ConvertType.cpp
parentb5a84ae09ab0bb59e43c5b4388fc1fe61cffec23 (diff)
downloadllvm-d8d91b2a25db8920c44a3dea36fc0eeff93bdfa0.zip
llvm-d8d91b2a25db8920c44a3dea36fc0eeff93bdfa0.tar.gz
llvm-d8d91b2a25db8920c44a3dea36fc0eeff93bdfa0.tar.bz2
[flang][hlfir] Support type descriptor for initialized character component
These compiler generated component descriptor include designators packaged as CLASS(*) for simplicity. HLFIR hit an assert in an std::get trying to recover an Expr<SomeChar> while translating the expression type. Use the dynamic type of the CLASS(*) expr in that case to recover the compiler length. Differential Revision: https://reviews.llvm.org/D144960
Diffstat (limited to 'flang/lib/Lower/ConvertType.cpp')
-rw-r--r--flang/lib/Lower/ConvertType.cpp21
1 files changed, 16 insertions, 5 deletions
diff --git a/flang/lib/Lower/ConvertType.cpp b/flang/lib/Lower/ConvertType.cpp
index 4fab5a5..d701749 100644
--- a/flang/lib/Lower/ConvertType.cpp
+++ b/flang/lib/Lower/ConvertType.cpp
@@ -433,11 +433,22 @@ struct TypeBuilderImpl {
// Do not use dynamic type length here. We would miss constant
// lengths opportunities because dynamic type only has the length
// if it comes from a declaration.
- auto charExpr =
- std::get<Fortran::evaluate::Expr<Fortran::evaluate::SomeCharacter>>(
- expr.u);
- if (auto constantLen = toInt64(charExpr.LEN()))
- return *constantLen;
+ if (const auto *charExpr = std::get_if<
+ Fortran::evaluate::Expr<Fortran::evaluate::SomeCharacter>>(
+ &expr.u)) {
+ if (auto constantLen = toInt64(charExpr->LEN()))
+ return *constantLen;
+ } else if (auto dynamicType = expr.GetType()) {
+ // When generating derived type type descriptor as structure constructor,
+ // semantics wraps designators to data component initialization into
+ // CLASS(*), regardless of their actual type.
+ // GetType() will recover the actual symbol type as the dynamic type, so
+ // getCharacterLength may be reached even if expr is packaged as an
+ // Expr<SomeDerived> instead of an Expr<SomeChar>.
+ // Just use the dynamic type here again to retrieve the length.
+ if (auto constantLen = toInt64(dynamicType->GetCharLength()))
+ return *constantLen;
+ }
return fir::SequenceType::getUnknownExtent();
}