[flang-commits] [flang] [flang] Fix bogus error on statement function (PR #89402)
via flang-commits
flang-commits at lists.llvm.org
Fri Apr 19 08:29:09 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-flang-semantics
Author: Peter Klausler (klausler)
<details>
<summary>Changes</summary>
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.
---
Full diff: https://github.com/llvm/llvm-project/pull/89402.diff
2 Files Affected:
- (modified) flang/lib/Semantics/resolve-names.cpp (+1-1)
- (modified) flang/test/Semantics/stmt-func02.f90 (+13-2)
``````````diff
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
``````````
</details>
https://github.com/llvm/llvm-project/pull/89402
More information about the flang-commits
mailing list