[flang-commits] [flang] 1fae146 - [flang] Fix USE rename

Leandro Lupori via flang-commits flang-commits at lists.llvm.org
Tue Feb 14 05:05:48 PST 2023


Author: Leandro Lupori
Date: 2023-02-14T10:04:56-03:00
New Revision: 1fae1464d7a78e7184f2b40f25e9491c87d93693

URL: https://github.com/llvm/llvm-project/commit/1fae1464d7a78e7184f2b40f25e9491c87d93693
DIFF: https://github.com/llvm/llvm-project/commit/1fae1464d7a78e7184f2b40f25e9491c87d93693.diff

LOG: [flang] Fix USE rename

Fix USE rename when use-name and local-name are the same.
Previously, the associated symbol was being removed from scope.

Operator rename implementation needed no change, because, as it
doesn't call AddUseRename(), symbol erasure is skipped.

Fixes #60223

Reviewed By: klausler

Differential Revision: https://reviews.llvm.org/D143933

Added: 
    flang/test/Semantics/resolve116.f90

Modified: 
    flang/lib/Semantics/resolve-names.cpp

Removed: 
    


################################################################################
diff  --git a/flang/lib/Semantics/resolve-names.cpp b/flang/lib/Semantics/resolve-names.cpp
index 4cd6905f62350..fd425147c6c56 100644
--- a/flang/lib/Semantics/resolve-names.cpp
+++ b/flang/lib/Semantics/resolve-names.cpp
@@ -2718,7 +2718,7 @@ bool ModuleVisitor::Pre(const parser::Rename::Names &x) {
   const auto &useName{std::get<1>(x.t)};
   AddUseRename(useName.source);
   SymbolRename rename{AddUse(localName.source, useName.source)};
-  if (rename.use) {
+  if (rename.use && localName.source != useName.source) {
     EraseRenamedSymbol(*rename.use);
   }
   Resolve(useName, rename.use);

diff  --git a/flang/test/Semantics/resolve116.f90 b/flang/test/Semantics/resolve116.f90
new file mode 100644
index 0000000000000..a46b677396fc0
--- /dev/null
+++ b/flang/test/Semantics/resolve116.f90
@@ -0,0 +1,24 @@
+! RUN: %python %S/test_errors.py %s %flang_fc1
+! Test rename to the same name.
+module m1
+  integer, allocatable :: a(:)
+
+  interface operator(.add.)
+    module procedure add
+  end interface
+
+contains
+  integer function add(a, b)
+    integer, intent(in) :: a, b
+
+    add = a + b
+  end function
+end
+
+program p1
+  use m1, a => a, operator(.add.) => operator(.add.)
+
+  allocate(a(10))
+  deallocate(a)
+  print *, 2 .add. 2
+end


        


More information about the flang-commits mailing list