[flang-commits] [flang] [flang] Fix bogus error on statement function (PR #89402)

Peter Klausler via flang-commits flang-commits at lists.llvm.org
Fri Apr 19 08:28:39 PDT 2024


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

When a statement function in a nested scope has a name that clashes with a name that exists in the host scope, the compiler can handle it correctly (with a portability warning)... unless the host scope acquired the name via USE association.  Fix.

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

>From 9b967f32c228905a548b7f824bff0dddbdf851ac Mon Sep 17 00:00:00 2001
From: Peter Klausler <pklausler at nvidia.com>
Date: Fri, 19 Apr 2024 08:21:15 -0700
Subject: [PATCH] [flang] Fix bogus error on statement function

When a statement function in a nested scope has a name that
clashes with a name that exists in the host scope, the compiler
can handle it correctly (with a portability warning)... unless
the host scope acquired the name via USE association.  Fix.

Fixes https://github.com/llvm/llvm-project/issues/88678.
---
 flang/lib/Semantics/resolve-names.cpp |  2 +-
 flang/test/Semantics/stmt-func02.f90  | 15 +++++++++++++--
 2 files changed, 14 insertions(+), 3 deletions(-)

diff --git a/flang/lib/Semantics/resolve-names.cpp b/flang/lib/Semantics/resolve-names.cpp
index f0198cb792280a..d0b2deccc7f179 100644
--- a/flang/lib/Semantics/resolve-names.cpp
+++ b/flang/lib/Semantics/resolve-names.cpp
@@ -3650,7 +3650,7 @@ bool SubprogramVisitor::HandleStmtFunction(const parser::StmtFunctionStmt &x) {
       misparsedStmtFuncFound_ = true;
       return false;
     }
-    if (DoesScopeContain(&ultimate.owner(), currScope())) {
+    if (IsHostAssociated(*symbol, currScope())) {
       if (context().ShouldWarn(
               common::LanguageFeature::StatementFunctionExtensions)) {
         Say(name,
diff --git a/flang/test/Semantics/stmt-func02.f90 b/flang/test/Semantics/stmt-func02.f90
index 0f4e8c034f659a..bfed280ded58d1 100644
--- a/flang/test/Semantics/stmt-func02.f90
+++ b/flang/test/Semantics/stmt-func02.f90
@@ -1,5 +1,12 @@
 ! RUN: %python %S/test_errors.py %s %flang_fc1 -pedantic
-module m
+module m1
+ contains
+  real function rf2(x)
+    rf2 = x
+  end
+end
+module m2
+  use m1
   real, target :: x = 1.
  contains
   function rpf(x)
@@ -18,7 +25,11 @@ subroutine test1
   end
   subroutine test2
     !PORTABILITY: Name 'rf' from host scope should have a type declaration before its local statement function definition
-    rf(x) = 3.
+    rf(x) = 1.
+  end
+  subroutine test2b
+    !PORTABILITY: Name 'rf2' from host scope should have a type declaration before its local statement function definition
+    rf2(x) = 1.
   end
   subroutine test3
     external sf



More information about the flang-commits mailing list