[flang-commits] [flang] [flang] Fix bad parse tree rewrite into a substring (PR #98407)
Peter Klausler via flang-commits
flang-commits at lists.llvm.org
Wed Jul 10 16:02:45 PDT 2024
https://github.com/klausler created https://github.com/llvm/llvm-project/pull/98407
Data designators like "a(j:k)" are parsed into array section references, but once rank and type information is in hand, some of them turn out to actually be substring references. The code that recognizes these cases was suffering from a "false positive" in the case of a construct entity in a SELECT RANK construct due to the use of a predicate member function (Symbol::IsObjectArray) that only works on ObjectEntityDetails symbols. Fix the test to use the more general Symbol::Rank() member function.
>From df3133b1ca8c3a69d9c798e4f55a0f136f347905 Mon Sep 17 00:00:00 2001
From: Peter Klausler <pklausler at nvidia.com>
Date: Wed, 10 Jul 2024 15:57:56 -0700
Subject: [PATCH] [flang] Fix bad parse tree rewrite into a substring
Data designators like "a(j:k)" are parsed into array section
references, but once rank and type information is in hand, some
of them turn out to actually be substring references. The code
that recognizes these cases was suffering from a "false positive"
in the case of a construct entity in a SELECT RANK construct due
to the use of a predicate member function (Symbol::IsObjectArray) that
only works on ObjectEntityDetails symbols. Fix the test to use
the more general Symbol::Rank() member function.
---
flang/lib/Semantics/expression.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/flang/lib/Semantics/expression.cpp b/flang/lib/Semantics/expression.cpp
index 2202639a92e43..90900d9acb6ad 100644
--- a/flang/lib/Semantics/expression.cpp
+++ b/flang/lib/Semantics/expression.cpp
@@ -523,7 +523,7 @@ static std::optional<parser::Substring> FixMisparsedSubstringDataRef(
parser::GetLastName(arrElement.base).symbol}) {
const Symbol &ultimate{symbol->GetUltimate()};
if (const semantics::DeclTypeSpec *type{ultimate.GetType()}) {
- if (!ultimate.IsObjectArray() &&
+ if (ultimate.Rank() == 0 &&
type->category() == semantics::DeclTypeSpec::Character) {
// The ambiguous S(j:k) was parsed as an array section
// reference, but it's now clear that it's a substring.
More information about the flang-commits
mailing list