[flang-commits] [flang] bdd7b4c - [Flang][Semantics] Throw diagnostics for identical entry and result names. (#198500)
via flang-commits
flang-commits at lists.llvm.org
Thu Jun 4 00:08:02 PDT 2026
Author: ShashwathiNavada
Date: 2026-06-04T12:37:58+05:30
New Revision: bdd7b4cc2a0c9a8c58e4025edae079ce6af73aa0
URL: https://github.com/llvm/llvm-project/commit/bdd7b4cc2a0c9a8c58e4025edae079ce6af73aa0
DIFF: https://github.com/llvm/llvm-project/commit/bdd7b4cc2a0c9a8c58e4025edae079ce6af73aa0.diff
LOG: [Flang][Semantics] Throw diagnostics for identical entry and result names. (#198500)
Fixes https://github.com/llvm/llvm-project/issues/198499
In flang entry name and result names cannot be same as per
[C1583](https://j3-fortran.org/doc/year/25/25-007r1.pdf).
Previously, Flang did not diagnose cases where the ENTRY name and RESULT
name were identical, e.g.
```
function m1f1()
integer :: m1f1
real :: m1f1e1
m1f1 = 0
entry m1f1e1() result(m1f1e1)
m1f1e1 = 0.1
end function
```
Added:
Modified:
flang/lib/Semantics/resolve-names.cpp
flang/test/Semantics/entry01.f90
Removed:
################################################################################
diff --git a/flang/lib/Semantics/resolve-names.cpp b/flang/lib/Semantics/resolve-names.cpp
index 2c21d18133368..a92d73ff1bc80 100644
--- a/flang/lib/Semantics/resolve-names.cpp
+++ b/flang/lib/Semantics/resolve-names.cpp
@@ -5230,8 +5230,14 @@ void SubprogramVisitor::CreateEntry(
return static_cast<const parser::Name *>(nullptr);
}()};
std::optional<SourceName> distinctResultName;
- if (resultName && resultName->source != entryName.source) {
- distinctResultName = resultName->source;
+ if (resultName) {
+ if (resultName->source == entryName.source) {
+ Say(*resultName,
+ "Explicit RESULT('%s') of ENTRY '%s' cannot have the same name as the ENTRY"_err_en_US,
+ resultName->source, entryName.source);
+ } else {
+ distinctResultName = resultName->source;
+ }
}
if (outer.IsModule() && !attrs.test(Attr::PRIVATE)) {
attrs.set(Attr::PUBLIC);
diff --git a/flang/test/Semantics/entry01.f90 b/flang/test/Semantics/entry01.f90
index 7176be169643c..624d608337443 100644
--- a/flang/test/Semantics/entry01.f90
+++ b/flang/test/Semantics/entry01.f90
@@ -266,7 +266,8 @@ subroutine s7(q,q)
!ERROR: Explicit RESULT('f8e1') of function 'f8' cannot have the same name as a distinct ENTRY into the same scope
function f8() result(f8e1)
entry f8e1()
- entry f8e2() result(f8e2) ! ok
+ !ERROR: Explicit RESULT('f8e2') of ENTRY 'f8e2' cannot have the same name as the ENTRY
+ entry f8e2() result(f8e2)
!ERROR: Explicit RESULT('f8e1') of function 'f8e3' cannot have the same name as a distinct ENTRY into the same scope
entry f8e3() result(f8e1)
!ERROR: ENTRY cannot have RESULT(f8) that is not a variable
More information about the flang-commits
mailing list