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

Peter Klausler via flang-commits flang-commits at lists.llvm.org
Wed Nov 22 13:05:32 PST 2023


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

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.

>From 7ec872ad8b5afda9b3cd9d013cccc6bf21032318 Mon Sep 17 00:00:00 2001
From: Peter Klausler <pklausler at nvidia.com>
Date: Wed, 22 Nov 2023 12:50:40 -0800
Subject: [PATCH] [flang] Address case of under-processed array symbol

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.
---
 flang/lib/Semantics/resolve-names.cpp |  5 +----
 flang/test/Semantics/symbol33.f90     | 11 +++++++++++
 2 files changed, 12 insertions(+), 4 deletions(-)
 create mode 100644 flang/test/Semantics/symbol33.f90

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



More information about the flang-commits mailing list