mirror of
https://github.com/llvm/llvm-project.git
synced 2025-04-17 16:06:40 +00:00

Internal procedures cannot be called directly from outside the host procedure, so there is no point giving them external linkage. The only reason flang did is because it is the default in MLIR. Giving external linkage to them: - prevents deleting them when not used/inlined by LLVM - causes bugs with shared libraries (at least on linux x86-64) because the call to the internal function could lead to a dynamic loader call that would overwrite r10 register (the static chain pointer) due to system calls and did not restore (it seems it does not expect r10 to be used for PLT calls). This patch gives internal linkage to internal procedures: Note: the llvm.linkage attribute name cannot be obtained via a getLinkageAttrName since it is not the same name as the one used in the LLVM dialect. It is just a placeholder defined in mlir/lib/Conversion/FuncToLLVM/FuncToLLVM.cpp until the func dialect gets a real linkage model. So simply avoid hard coding it too many times in lowering.
42 lines
1.1 KiB
Fortran
42 lines
1.1 KiB
Fortran
! RUN: bbc -hlfir=false %s -o - | FileCheck %s
|
|
|
|
! CHECK-LABEL: _QQmain
|
|
program test1
|
|
! CHECK-DAG: %[[TMP:.*]] = fir.alloca
|
|
! CHECK-DAG: %[[TEN:.*]] = arith.constant
|
|
! CHECK: fir.store %[[TEN]] to %[[TMP]]
|
|
! CHECK-NEXT: fir.call @_QFPfoo
|
|
call foo(10)
|
|
contains
|
|
|
|
! CHECK-LABEL: func private @_QFPfoo
|
|
subroutine foo(avar1)
|
|
integer :: avar1
|
|
! integer :: my_data, my_data2
|
|
! DATA my_data / 150 /
|
|
! DATA my_data2 / 150 /
|
|
! print *, my_data, my_data2
|
|
print *, avar1
|
|
end subroutine
|
|
! CHECK: }
|
|
end program test1
|
|
|
|
! CHECK-LABEL: func @_QPsub2
|
|
function sub2(r)
|
|
real :: r(20)
|
|
! CHECK: %[[coor:.*]] = fir.coordinate_of %arg0
|
|
! CHECK: = fir.call @_QPf(%[[coor]]) {{.*}}: (!fir.ref<f32>) -> f32
|
|
sub2 = f(r(1))
|
|
! CHECK: return %{{.*}} : f32
|
|
end function sub2
|
|
|
|
! Test TARGET attribute lowering
|
|
! CHECK-LABEL: func @_QPtest_target(
|
|
! CHECK-SAME: !fir.ref<i32> {fir.bindc_name = "i", fir.target},
|
|
! CHECK-SAME: !fir.box<!fir.array<?xf32>> {fir.bindc_name = "x", fir.target})
|
|
subroutine test_target(i, x)
|
|
integer, target :: i
|
|
real, target :: x(:)
|
|
print *, xs, xa
|
|
end subroutine
|