Skip to content

[flang] Fix separate MODULE PROCEDURE when binding label exists #82686

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
Mar 1, 2024

Conversation

klausler
Copy link
Contributor

When a separate module procedure is defined with a MODULE PROCEDURE and its corresponding interface has a binding label, the compiler was emitting an error about mismatching binding labels because the binding label wasn't being copied into the subprogram's definition.

When a separate module procedure is defined with a MODULE PROCEDURE
and its corresponding interface has a binding label, the compiler
was emitting an error about mismatching binding labels because the
binding label wasn't being copied into the subprogram's definition.
@klausler klausler requested a review from vdonaldson February 22, 2024 20:39
@llvmbot llvmbot added flang Flang issues not falling into any other category flang:semantics labels Feb 22, 2024
@llvmbot
Copy link
Member

llvmbot commented Feb 22, 2024

@llvm/pr-subscribers-flang-semantics

Author: Peter Klausler (klausler)

Changes

When a separate module procedure is defined with a MODULE PROCEDURE and its corresponding interface has a binding label, the compiler was emitting an error about mismatching binding labels because the binding label wasn't being copied into the subprogram's definition.


Full diff: https://github.com/llvm/llvm-project/pull/82686.diff

2 Files Affected:

  • (modified) flang/lib/Semantics/resolve-names.cpp (+6-1)
  • (modified) flang/test/Semantics/separate-mp02.f90 (+4)
diff --git a/flang/lib/Semantics/resolve-names.cpp b/flang/lib/Semantics/resolve-names.cpp
index 36deab969456d0..131585b067cb70 100644
--- a/flang/lib/Semantics/resolve-names.cpp
+++ b/flang/lib/Semantics/resolve-names.cpp
@@ -4216,7 +4216,12 @@ bool SubprogramVisitor::BeginMpSubprogram(const parser::Name &name) {
     EraseSymbol(name);
     Symbol &newSymbol{MakeSymbol(name, SubprogramDetails{})};
     PushScope(Scope::Kind::Subprogram, &newSymbol);
-    newSymbol.get<SubprogramDetails>().set_moduleInterface(*symbol);
+    auto &newSubprogram{newSymbol.get<SubprogramDetails>()};
+    newSubprogram.set_moduleInterface(*symbol);
+    auto &subprogram{symbol->get<SubprogramDetails>()};
+    if (const auto *name{subprogram.bindName()}) {
+      newSubprogram.set_bindName(std::string{*name});
+    }
     newSymbol.attrs() |= symbol->attrs();
     newSymbol.set(symbol->test(Symbol::Flag::Subroutine)
             ? Symbol::Flag::Subroutine
diff --git a/flang/test/Semantics/separate-mp02.f90 b/flang/test/Semantics/separate-mp02.f90
index 5d13b6b693c8f7..c63ab6f41a1326 100644
--- a/flang/test/Semantics/separate-mp02.f90
+++ b/flang/test/Semantics/separate-mp02.f90
@@ -148,6 +148,8 @@ module subroutine s5() bind(c)
     end
     module subroutine s6() bind(c)
     end
+    module subroutine s7() bind(c, name="s7")
+    end
   end interface
 end
 
@@ -172,6 +174,8 @@ module subroutine s5() bind(c, name=" s5")
   !ERROR: Module subprogram 's6' has binding label 'not_s6' but the corresponding interface body has 's6'
   module subroutine s6() bind(c, name="not_s6")
   end
+  module procedure s7
+  end
 end
 
 

@klausler klausler merged commit 8f14149 into llvm:main Mar 1, 2024
@klausler klausler deleted the bug1524 branch March 1, 2024 22:57
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.

3 participants