[flang-commits] [flang] [flang] Fix bad parse tree rewrite into a substring (PR #98407)

via flang-commits flang-commits at lists.llvm.org
Wed Jul 10 16:03:16 PDT 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-flang-semantics

Author: Peter Klausler (klausler)

<details>
<summary>Changes</summary>

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.

---
Full diff: https://github.com/llvm/llvm-project/pull/98407.diff


1 Files Affected:

- (modified) flang/lib/Semantics/expression.cpp (+1-1) 


``````````diff
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.

``````````

</details>


https://github.com/llvm/llvm-project/pull/98407


More information about the flang-commits mailing list