From df3133b1ca8c3a69d9c798e4f55a0f136f347905 Mon Sep 17 00:00:00 2001 From: Peter Klausler 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 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.