[flang-commits] [flang] ed03417 - [flang] retain binding label of entry subprograms

Jean Perier via flang-commits flang-commits at lists.llvm.org
Mon May 9 00:51:54 PDT 2022


Author: Jean Perier
Date: 2022-05-09T09:50:17+02:00
New Revision: ed0341788af290f4028c0e200f4a8854bfe46e7d

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

LOG: [flang] retain binding label of entry subprograms

When processing an entry-stmt in name resolution, attrs_ was
reset before SetBindNameOn was called, causing the symbol to lose
the binding label information.

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

Added: 
    

Modified: 
    flang/lib/Semantics/resolve-names.cpp
    flang/test/Lower/program-units-fir-mangling.f90

Removed: 
    


################################################################################
diff  --git a/flang/lib/Semantics/resolve-names.cpp b/flang/lib/Semantics/resolve-names.cpp
index 076e0bff4aea..ed77d57b4f8c 100644
--- a/flang/lib/Semantics/resolve-names.cpp
+++ b/flang/lib/Semantics/resolve-names.cpp
@@ -841,6 +841,7 @@ class SubprogramVisitor : public virtual ScopeHandler, public InterfaceVisitor {
       const parser::LanguageBindingSpec * = nullptr);
   Symbol *GetSpecificFromGeneric(const parser::Name &);
   SubprogramDetails &PostSubprogramStmt(const parser::Name &);
+  void PostEntryStmt(const parser::EntryStmt &stmt);
 };
 
 class DeclarationVisitor : public ArraySpecVisitor,
@@ -3321,7 +3322,11 @@ SubprogramDetails &SubprogramVisitor::PostSubprogramStmt(
 }
 
 void SubprogramVisitor::Post(const parser::EntryStmt &stmt) {
-  auto attrs{EndAttrs()}; // needs to be called even if early return
+  PostEntryStmt(stmt);
+  EndAttrs();
+}
+
+void SubprogramVisitor::PostEntryStmt(const parser::EntryStmt &stmt) {
   Scope &inclusiveScope{InclusiveScope()};
   const Symbol *subprogram{inclusiveScope.symbol()};
   if (!subprogram) {
@@ -3435,8 +3440,8 @@ void SubprogramVisitor::Post(const parser::EntryStmt &stmt) {
   Symbol::Flag subpFlag{
       inFunction ? Symbol::Flag::Function : Symbol::Flag::Subroutine};
   Scope &outer{inclusiveScope.parent()}; // global or module scope
-  if (outer.IsModule() && !attrs.test(Attr::PRIVATE)) {
-    attrs.set(Attr::PUBLIC);
+  if (outer.IsModule() && attrs_ && !attrs_->test(Attr::PRIVATE)) {
+    attrs_->set(Attr::PUBLIC);
   }
   if (Symbol * extant{FindSymbol(outer, name)}) {
     if (!HandlePreviousCalls(name, *extant, subpFlag)) {
@@ -3450,7 +3455,7 @@ void SubprogramVisitor::Post(const parser::EntryStmt &stmt) {
     }
   }
 
-  Symbol *entrySymbol{&MakeSymbol(outer, name.source, attrs)};
+  Symbol *entrySymbol{&MakeSymbol(outer, name.source, GetAttrs())};
   if (auto *generic{entrySymbol->detailsIf<GenericDetails>()}) {
     CHECK(generic->specific());
     entrySymbol = generic->specific();

diff  --git a/flang/test/Lower/program-units-fir-mangling.f90 b/flang/test/Lower/program-units-fir-mangling.f90
index 769deefc8f95..bf360768ae82 100644
--- a/flang/test/Lower/program-units-fir-mangling.f90
+++ b/flang/test/Lower/program-units-fir-mangling.f90
@@ -151,4 +151,38 @@ function alpha() bind(c, name =" bEtA ")
 ! CHECK: }
 end function
 
+! CHECK-LABEL: func @bc1() attributes {fir.sym_name = "_QPbind_c_s"} {
+subroutine bind_c_s() Bind(C,Name='bc1')
+  ! CHECK: return
+end subroutine bind_c_s
+
+! CHECK-LABEL: func @_QPbind_c_s() {
+subroutine bind_c_s()
+  ! CHECK: fir.call @_QPbind_c_q() : () -> ()
+  ! CHECK: return
+  call bind_c_q
+end
+
+! CHECK-LABEL: func @_QPbind_c_q() {
+subroutine bind_c_q()
+  interface
+    subroutine bind_c_s() Bind(C, name='bc1')
+    end
+  end interface
+  ! CHECK: fir.call @bc1() : () -> ()
+  ! CHECK: return
+  call bind_c_s
+end
+
+! Test that BIND(C) label is taken into account for ENTRY symbols.
+! CHECK-LABEL: func @_QPsub_with_entries() {
+subroutine sub_with_entries
+! CHECK-LABEL: func @bar() attributes {fir.sym_name = "_QPsome_entry"} {
+ entry some_entry() bind(c, name="bar")
+! CHECK-LABEL: func @_QPnormal_entry() {
+ entry normal_entry()
+! CHECK-LABEL: func @some_other_entry() attributes {fir.sym_name = "_QPsome_other_entry"} {
+ entry some_other_entry() bind(c)
+end subroutine
+
 ! CHECK-LABEL: fir.global internal @_QFfooEpi : f32 {


        


More information about the flang-commits mailing list