Skip to content

[flang] Ensure component attributes affect characteristics #67465

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 16, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 20 additions & 10 deletions flang/include/flang/Evaluate/characteristics.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,18 +81,19 @@ class TypeAndShape {
bool operator!=(const TypeAndShape &that) const { return !(*this == that); }

static std::optional<TypeAndShape> Characterize(
const semantics::Symbol &, FoldingContext &, bool invariantOnly = false);
const semantics::Symbol &, FoldingContext &, bool invariantOnly = true);
static std::optional<TypeAndShape> Characterize(
const semantics::DeclTypeSpec &, FoldingContext &,
bool invariantOnly = false);
bool invariantOnly = true);
static std::optional<TypeAndShape> Characterize(
const ActualArgument &, FoldingContext &, bool invariantOnly = false);
const ActualArgument &, FoldingContext &, bool invariantOnly = true);

// General case for Expr<T>, &c.
template <typename A>
static std::optional<TypeAndShape> Characterize(
const A &x, FoldingContext &context, bool invariantOnly = false) {
if (const auto *symbol{UnwrapWholeSymbolDataRef(x)}) {
const A &x, FoldingContext &context, bool invariantOnly = true) {
const auto *symbol{UnwrapWholeSymbolOrComponentDataRef(x)};
if (symbol && !symbol->owner().IsDerivedType()) { // Whole variable
if (auto result{Characterize(*symbol, context, invariantOnly)}) {
return result;
}
Expand All @@ -106,6 +107,9 @@ class TypeAndShape {
}
}
}
if (symbol) { // component
result.AcquireAttrs(*symbol);
}
return std::move(result.Rewrite(context));
}
return std::nullopt;
Expand All @@ -116,15 +120,21 @@ class TypeAndShape {
static std::optional<TypeAndShape> Characterize(
const Designator<Type<TypeCategory::Character, KIND>> &x,
FoldingContext &context, bool invariantOnly = true) {
if (const auto *symbol{UnwrapWholeSymbolDataRef(x)}) {
const auto *symbol{UnwrapWholeSymbolOrComponentDataRef(x)};
if (symbol && !symbol->owner().IsDerivedType()) { // Whole variable
if (auto result{Characterize(*symbol, context, invariantOnly)}) {
return result;
}
}
if (auto type{x.GetType()}) {
TypeAndShape result{*type, GetShape(context, x, invariantOnly)};
if (auto length{x.LEN()}) {
result.set_LEN(std::move(*length));
if (type->category() == TypeCategory::Character) {
if (auto length{x.LEN()}) {
result.set_LEN(std::move(*length));
}
}
if (symbol) { // component
result.AcquireAttrs(*symbol);
}
return std::move(result.Rewrite(context));
}
Expand All @@ -133,7 +143,7 @@ class TypeAndShape {

template <typename A>
static std::optional<TypeAndShape> Characterize(const std::optional<A> &x,
FoldingContext &context, bool invariantOnly = false) {
FoldingContext &context, bool invariantOnly = true) {
if (x) {
return Characterize(*x, context, invariantOnly);
} else {
Expand All @@ -142,7 +152,7 @@ class TypeAndShape {
}
template <typename A>
static std::optional<TypeAndShape> Characterize(
A *ptr, FoldingContext &context, bool invariantOnly = false) {
A *ptr, FoldingContext &context, bool invariantOnly = true) {
if (ptr) {
return Characterize(std::as_const(*ptr), context, invariantOnly);
} else {
Expand Down