Internal linkage for private subroutines

Hi all,

In the code below, every function in module m is private by default, and only bar() is declared public:

module m

implicit none

private

public :: bar

integer :: arr1(42)

contains

subroutine foo(a)

integer :: a

arr1(1) = 2

end subroutine foo

subroutine bar(a)

integer :: a

call foo(a)

end subroutine bar

end module m

However, in the resulting LLVM IR, no function is declared with an attribute “internal”:

define void @m_foo_(i64* %a) !dbg !5 {

L.entry:

br label %L.LB2_313

L.LB2_313: ; preds = %L.entry

%0 = bitcast %struct_m_4_* @m_4 to i32*, !dbg !10

store i32 2, i32* %0, align 4, !dbg !10, !tbaa !12

ret void, !dbg !16

}

define void @m_bar_(i64* %a) !dbg !17 {

L.entry:

br label %L.LB3_314

L.LB3_314: ; preds = %L.entry

call void @m_foo_(i64* %a), !dbg !18

ret void, !dbg !20

}

Am I missing something? I tried to find where it might be implemented in flang by grepping the flang codebase for SC_STATIC but there’s just too many places. Any pointers would be much appreciated.

Alexey

This looks promising:

ll_write.cpp: fprintf(out, "define %s %s %s ", ll_get_linkage_string(function->linkage),

This concernes legacy flang, correct? (I ask because there are linkage issues with mlir as well)

Yes, the question is with respect to the legacy flang.

Best,
Alexey

For my example, I see that LLVM IR is printed in cgmain.cpp:build_routine_and_parameter_entries. However, what I’m looking for is the place where function linkage is decided. I see internal linkage for some of the functions in large Fortran modules but the pattern seems completely random to me.

Best,
Alexey