[flang-commits] [PATCH] D123733: [flang] Accept %KIND type parameter inquiries on %RE, %IM, &c.
Peter Klausler via Phabricator via flang-commits
flang-commits at lists.llvm.org
Wed Apr 13 13:22:48 PDT 2022
klausler created this revision.
klausler added a reviewer: vdonaldson.
klausler added a project: Flang.
Herald added a subscriber: jdoerfert.
Herald added a project: All.
klausler requested review of this revision.
The x%KIND inquiry needs to be supported when 'x' is itself
a complex part reference or a type parameter inquiry.
https://reviews.llvm.org/D123733
Files:
flang/lib/Semantics/expression.cpp
flang/lib/Semantics/resolve-names.cpp
Index: flang/lib/Semantics/resolve-names.cpp
===================================================================
--- flang/lib/Semantics/resolve-names.cpp
+++ flang/lib/Semantics/resolve-names.cpp
@@ -6271,6 +6271,18 @@
if (!base || !base->symbol) {
return nullptr;
}
+ if (auto *misc{base->symbol->detailsIf<MiscDetails>()}) {
+ if (component.source == "kind") {
+ if (misc->kind() == MiscDetails::Kind::ComplexPartRe ||
+ misc->kind() == MiscDetails::Kind::ComplexPartIm ||
+ misc->kind() == MiscDetails::Kind::KindParamInquiry ||
+ misc->kind() == MiscDetails::Kind::LenParamInquiry) {
+ // x%{re,im,kind,len}%kind
+ MakePlaceholder(component, MiscDetails::Kind::KindParamInquiry);
+ return &component;
+ }
+ }
+ }
auto &symbol{base->symbol->GetUltimate()};
if (!symbol.has<AssocEntityDetails>() && !ConvertToObjectEntity(symbol)) {
SayWithDecl(*base, symbol,
@@ -6282,25 +6294,24 @@
return nullptr; // should have already reported error
}
if (const IntrinsicTypeSpec * intrinsic{type->AsIntrinsic()}) {
- auto name{component.ToString()};
auto category{intrinsic->category()};
MiscDetails::Kind miscKind{MiscDetails::Kind::None};
- if (name == "kind") {
+ if (component.source == "kind") {
miscKind = MiscDetails::Kind::KindParamInquiry;
} else if (category == TypeCategory::Character) {
- if (name == "len") {
+ if (component.source == "len") {
miscKind = MiscDetails::Kind::LenParamInquiry;
}
} else if (category == TypeCategory::Complex) {
- if (name == "re") {
+ if (component.source == "re") {
miscKind = MiscDetails::Kind::ComplexPartRe;
- } else if (name == "im") {
+ } else if (component.source == "im") {
miscKind = MiscDetails::Kind::ComplexPartIm;
}
}
if (miscKind != MiscDetails::Kind::None) {
MakePlaceholder(component, miscKind);
- return nullptr;
+ return &component;
}
} else if (const DerivedTypeSpec * derived{type->AsDerived()}) {
if (const Scope * scope{derived->scope()}) {
Index: flang/lib/Semantics/expression.cpp
===================================================================
--- flang/lib/Semantics/expression.cpp
+++ flang/lib/Semantics/expression.cpp
@@ -1069,7 +1069,8 @@
}
} else if (auto *details{sym->detailsIf<semantics::MiscDetails>()}) {
// special part-ref: %re, %im, %kind, %len
- // Type errors are detected and reported in semantics.
+ // Type errors on the base of %re/%im/%len are detected and
+ // reported in name resolution.
using MiscKind = semantics::MiscDetails::Kind;
MiscKind kind{details->kind()};
if (kind == MiscKind::ComplexPartRe || kind == MiscKind::ComplexPartIm) {
@@ -1090,7 +1091,6 @@
}
} else if (kind == MiscKind::KindParamInquiry ||
kind == MiscKind::LenParamInquiry) {
- // Convert x%KIND -> intrinsic KIND(x), x%LEN -> intrinsic LEN(x)
ActualArgument arg{std::move(*base)};
SetArgSourceLocation(arg, name);
return MakeFunctionRef(name, ActualArguments{std::move(arg)});
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D123733.422636.patch
Type: text/x-patch
Size: 3171 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/flang-commits/attachments/20220413/5f03fb0b/attachment-0001.bin>
More information about the flang-commits
mailing list