diff --git a/flang/lib/Semantics/resolve-names.cpp b/flang/lib/Semantics/resolve-names.cpp --- a/flang/lib/Semantics/resolve-names.cpp +++ b/flang/lib/Semantics/resolve-names.cpp @@ -841,6 +841,7 @@ 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 @@ } 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 @@ 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 @@ } } - Symbol *entrySymbol{&MakeSymbol(outer, name.source, attrs)}; + Symbol *entrySymbol{&MakeSymbol(outer, name.source, GetAttrs())}; if (auto *generic{entrySymbol->detailsIf()}) { 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 --- a/flang/test/Lower/program-units-fir-mangling.f90 +++ b/flang/test/Lower/program-units-fir-mangling.f90 @@ -151,4 +151,38 @@ ! 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 {