[flang-commits] [flang] [flang] Address case of under-processed array symbol (PR #73169)

via flang-commits flang-commits at lists.llvm.org
Wed Nov 22 13:06:01 PST 2023


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-flang-semantics

Author: Peter Klausler (klausler)

<details>
<summary>Changes</summary>

Array element references are frequently parsed as function references due to the ambiguous syntax of Fortran, and the parse tree is repaired by semantics once the relevant symbol table entries are in hand. This patch fixes a case in which the correction takes a path that leaves the type of a symbol undetermined, leading to later spurious errors in expression analysis.

Fixes https://github.com/llvm/llvm-project/issues/68652.

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


2 Files Affected:

- (modified) flang/lib/Semantics/resolve-names.cpp (+1-4) 
- (added) flang/test/Semantics/symbol33.f90 (+11) 


``````````diff
diff --git a/flang/lib/Semantics/resolve-names.cpp b/flang/lib/Semantics/resolve-names.cpp
index 8f15f2f51da7c89..55a211aeacf7c81 100644
--- a/flang/lib/Semantics/resolve-names.cpp
+++ b/flang/lib/Semantics/resolve-names.cpp
@@ -7708,7 +7708,6 @@ void ResolveNamesVisitor::HandleProcedureName(
   } else if (CheckUseError(name)) {
     // error was reported
   } else {
-    auto &nonUltimateSymbol{*symbol};
     symbol = &Resolve(name, symbol)->GetUltimate();
     CheckEntryDummyUse(name.source, symbol);
     bool convertedToProcEntity{ConvertToProcEntity(*symbol)};
@@ -7733,9 +7732,7 @@ void ResolveNamesVisitor::HandleProcedureName(
       // is created for the current scope.
       // Operate on non ultimate symbol so that HostAssocDetails are also
       // created for symbols used associated in the host procedure.
-      if (IsUplevelReference(nonUltimateSymbol)) {
-        MakeHostAssocSymbol(name, nonUltimateSymbol);
-      }
+      ResolveName(name);
     } else if (symbol->test(Symbol::Flag::Implicit)) {
       Say(name,
           "Use of '%s' as a procedure conflicts with its implicit definition"_err_en_US);
diff --git a/flang/test/Semantics/symbol33.f90 b/flang/test/Semantics/symbol33.f90
new file mode 100644
index 000000000000000..fbb5321b8854dfd
--- /dev/null
+++ b/flang/test/Semantics/symbol33.f90
@@ -0,0 +1,11 @@
+! RUN: %python %S/test_symbols.py %s %flang_fc1
+! Ensure that a misparsed function reference that turns out to be an
+! array element reference still applies implicit typing, &c.
+!DEF: /subr (Subroutine) Subprogram
+subroutine subr
+  !DEF: /subr/moo (Implicit) ObjectEntity INTEGER(4)
+  common //moo(1)
+  !DEF: /subr/a ObjectEntity REAL(4)
+  !REF: /subr/moo
+  real a(moo(1))
+end subroutine

``````````

</details>


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


More information about the flang-commits mailing list