[flang] Fix to UnwrapConvertedExpr()

The utility UnwrapConvertedExpr() was failing to unwrap a
converted TypeParamInquiry operation when called from runtime
derived type description table construction, leading to an
abort in semantics.

Differential Revision: https://reviews.llvm.org/D125119
This commit is contained in:
Peter Klausler 2022-05-02 16:56:20 -07:00
parent b554c643c5
commit 6f14dbedd9
1 changed files with 14 additions and 8 deletions

View File

@ -219,16 +219,22 @@ auto UnwrapConvertedExpr(B &x) -> common::Constify<A, B> * {
} else if constexpr (std::is_same_v<Ty, Expr<SomeType>>) { } else if constexpr (std::is_same_v<Ty, Expr<SomeType>>) {
return common::visit( return common::visit(
[](auto &x) { return UnwrapConvertedExpr<A>(x); }, x.u); [](auto &x) { return UnwrapConvertedExpr<A>(x); }, x.u);
} else if constexpr (!common::HasMember<A, TypelessExpression>) { } else {
using Result = ResultType<A>; using DesiredResult = ResultType<A>;
if constexpr (std::is_same_v<Ty, Expr<Result>> || if constexpr (std::is_same_v<Ty, Expr<DesiredResult>> ||
std::is_same_v<Ty, Expr<SomeKind<Result::category>>>) { std::is_same_v<Ty, Expr<SomeKind<DesiredResult::category>>>) {
return common::visit( return common::visit(
[](auto &x) { return UnwrapConvertedExpr<A>(x); }, x.u); [](auto &x) { return UnwrapConvertedExpr<A>(x); }, x.u);
} else if constexpr (std::is_same_v<Ty, Parentheses<Result>> || } else {
std::is_same_v<Ty, Convert<Result, Result::category>>) { using ThisResult = ResultType<B>;
return common::visit( if constexpr (std::is_same_v<Ty, Expr<ThisResult>>) {
[](auto &x) { return UnwrapConvertedExpr<A>(x); }, x.left().u); return common::visit(
[](auto &x) { return UnwrapConvertedExpr<A>(x); }, x.u);
} else if constexpr (std::is_same_v<Ty, Parentheses<ThisResult>> ||
std::is_same_v<Ty, Convert<ThisResult, DesiredResult::category>>) {
return common::visit(
[](auto &x) { return UnwrapConvertedExpr<A>(x); }, x.left().u);
}
} }
} }
return nullptr; return nullptr;