Skip to content

[flang] Address case of under-processed array symbol #73169

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 30, 2023

Conversation

klausler
Copy link
Contributor

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 #68652.

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 llvm#68652.
@klausler klausler requested a review from psteinfeld November 22, 2023 21:05
@llvmbot llvmbot added flang Flang issues not falling into any other category flang:semantics labels Nov 22, 2023
@llvmbot
Copy link
Member

llvmbot commented Nov 22, 2023

@llvm/pr-subscribers-flang-semantics

Author: Peter Klausler (klausler)

Changes

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 #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 --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

Copy link
Contributor

@psteinfeld psteinfeld left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great!

@klausler klausler merged commit fddadd2 into llvm:main Nov 30, 2023
@klausler klausler deleted the bug68652 branch November 30, 2023 21:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
flang:semantics flang Flang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Flang] Compilation error of adjustable explicit-shape array
3 participants