251 lines · plain
1! RUN: bbc %s -o "-" -emit-fir | FileCheck %s2 3! CHECK-LABEL: func @_QPsub() {4subroutine sub()5! CHECK: }6end subroutine7 8! CHECK-LABEL: func @_QPasubroutine() {9subroutine AsUbRoUtInE()10! CHECK: }11end subroutine12 13! CHECK-LABEL: func @_QPfoo() -> f32 {14function foo()15 real(4) :: foo16 real :: pi = 3.1415917! CHECK: }18end function19 20 21! CHECK-LABEL: func @_QPfunctn() -> f32 {22function functn23 real, parameter :: pi = 3.1424! CHECK: }25end function26 27 28module testMod29contains30 ! CHECK-LABEL: func @_QMtestmodPsub() {31 subroutine sub()32 ! CHECK: }33 end subroutine34 35 ! CHECK-LABEL: func @_QMtestmodPfoo() -> f32 {36 function foo()37 real(4) :: foo38 ! CHECK: }39 end function40end module41 42 43! CHECK-LABEL: func @_QPfoo2()44function foo2()45 real(4) :: foo246contains47 ! CHECK-LABEL: func private @_QFfoo2Psub() {{.*}} {48 subroutine sub()49 ! CHECK: }50 end subroutine51 52 ! CHECK-LABEL: func private @_QFfoo2Pfoo() {{.*}} {53 subroutine foo()54 ! CHECK: }55 end subroutine56end function57 58! CHECK-LABEL: func @_QPsub2()59subroutine sUb2()60contains61 ! CHECK-LABEL: func private @_QFsub2Psub() {{.*}} {62 subroutine sub()63 ! CHECK: }64 end subroutine65 66 ! CHECK-LABEL: func private @_QFsub2Pfoo() {{.*}} {67 subroutine Foo()68 ! CHECK: }69 end subroutine70end subroutine71 72module testMod273contains74 ! CHECK-LABEL: func @_QMtestmod2Psub()75 subroutine sub()76 contains77 ! CHECK-LABEL: func private @_QMtestmod2FsubPsubsub() {{.*}} {78 subroutine subSub()79 ! CHECK: }80 end subroutine81 end subroutine82end module83 84 85module color_points86 interface87 module subroutine draw()88 end subroutine89 module function erase()90 integer(4) :: erase91 end function92 end interface93end module color_points94 95submodule (color_points) color_points_a96contains97 ! CHECK-LABEL: func @_QMcolor_pointsScolor_points_aPsub() {98 subroutine sub99 end subroutine100 ! CHECK: }101end submodule102 103submodule (color_points:color_points_a) impl104contains105 ! CHECK-LABEL: func @_QMcolor_pointsScolor_points_aSimplPfoo()106 subroutine foo107 contains108 ! CHECK-LABEL: func private @_QMcolor_pointsScolor_points_aSimplFfooPbar() {{.*}} {109 subroutine bar110 ! CHECK: }111 end subroutine112 end subroutine113 ! CHECK-LABEL: func @_QMcolor_pointsPdraw() {114 module subroutine draw()115 end subroutine116 !FIXME func @_QMcolor_pointsPerase() -> i32 {117 module procedure erase118 ! CHECK: }119 end procedure120end submodule121 122! CHECK-LABEL: func @_QPshould_not_collide() {123subroutine should_not_collide()124! CHECK: }125end subroutine126 127! CHECK-LABEL: func @_QQmain() attributes {fir.bindc_name = "TEST"} {128program test129! CHECK: }130contains131! CHECK-LABEL: func private @_QFPshould_not_collide() {{.*}} {132subroutine should_not_collide()133! CHECK: }134end subroutine135end program136 137! CHECK-LABEL: func @omp_get_num_threads() -> f32 attributes {fir.bindc_name = "omp_get_num_threads", fir.proc_attrs = #fir.proc_attrs<bind_c>} {138function omp_get_num_threads() bind(c)139! CHECK: }140end function141 142! CHECK-LABEL: func @get_threads() -> f32 attributes {fir.bindc_name = "get_threads", fir.proc_attrs = #fir.proc_attrs<bind_c>} {143function omp_get_num_threads_1() bind(c, name ="get_threads")144! CHECK: }145end function146 147! CHECK-LABEL: func @bEtA() -> f32 attributes {fir.bindc_name = "bEtA", fir.proc_attrs = #fir.proc_attrs<bind_c>} {148function alpha() bind(c, name =" bEtA ")149! CHECK: }150end function151 152! CHECK-LABEL: func @bc1() attributes {fir.bindc_name = "bc1", fir.proc_attrs = #fir.proc_attrs<bind_c>} {153subroutine bind_c_s() Bind(C,Name='bc1')154 ! CHECK: return155end subroutine bind_c_s156 157! CHECK-LABEL: func @_QPbind_c_s() {158subroutine bind_c_s()159 ! CHECK: fir.call @_QPbind_c_q() {{.*}}: () -> ()160 ! CHECK: return161 call bind_c_q162end163 164! CHECK-LABEL: func @_QPbind_c_q() {165subroutine bind_c_q()166 interface167 subroutine bind_c_s() Bind(C, name='bc1')168 end169 end interface170 ! CHECK: fir.call @bc1() {{.*}}: () -> ()171 ! CHECK: return172 call bind_c_s173end174 175! Test that BIND(C) label is taken into account for ENTRY symbols.176! CHECK-LABEL: func @_QPsub_with_entries() {177subroutine sub_with_entries178! CHECK-LABEL: func @bar() attributes {fir.bindc_name = "bar", fir.proc_attrs = #fir.proc_attrs<bind_c>} {179 entry some_entry() bind(c, name="bar")180! CHECK-LABEL: func @_QPnormal_entry() {181 entry normal_entry()182! CHECK-LABEL: func @some_other_entry() attributes {fir.bindc_name = "some_other_entry", fir.proc_attrs = #fir.proc_attrs<bind_c>} {183 entry some_other_entry() bind(c)184end subroutine185 186! Test that semantics constructs binding labels with local name resolution187module testMod3188 character*(*), parameter :: foo = "bad!!"189 character*(*), parameter :: ok = "ok"190 interface191 real function f1() bind(c,name=ok//'1')192 import ok193 end function194 subroutine s1() bind(c,name=ok//'2')195 import ok196 end subroutine197 end interface198 contains199! CHECK-LABEL: func @ok3() -> f32 attributes {fir.bindc_name = "ok3", fir.proc_attrs = #fir.proc_attrs<bind_c>} {200 real function f2() bind(c,name=foo//'3')201 character*(*), parameter :: foo = ok202! CHECK: fir.call @ok1() {{.*}}: () -> f32203! CHECK-LABEL: func @ok4() -> f32 attributes {fir.bindc_name = "ok4", fir.proc_attrs = #fir.proc_attrs<bind_c>} {204 entry f3() bind(c,name=foo//'4')205! CHECK: fir.call @ok1() {{.*}}: () -> f32206 f2 = f1()207 end function208! CHECK-LABEL: func @ok5() attributes {fir.bindc_name = "ok5", fir.proc_attrs = #fir.proc_attrs<bind_c>} {209 subroutine s2() bind(c,name=foo//'5')210 character*(*), parameter :: foo = ok211! CHECK: fir.call @ok2() {{.*}}: () -> ()212! CHECK-LABEL: func @ok6() attributes {fir.bindc_name = "ok6", fir.proc_attrs = #fir.proc_attrs<bind_c>} {213 entry s3() bind(c,name=foo//'6')214! CHECK: fir.call @ok2() {{.*}}: () -> ()215 continue ! force end of specification part216! CHECK-LABEL: func @ok7() attributes {fir.bindc_name = "ok7", fir.proc_attrs = #fir.proc_attrs<bind_c>} {217 entry s4() bind(c,name=foo//'7')218! CHECK: fir.call @ok2() {{.*}}: () -> ()219 call s1220 end subroutine221end module222 223 224! CHECK-LABEL: func @_QPnest1225subroutine nest1226 ! CHECK: fir.call @_QFnest1Pinner()227 call inner228contains229 ! CHECK-LABEL: func private @_QFnest1Pinner230 subroutine inner231 ! CHECK: %[[V_0:[0-9]+]] = fir.address_of(@_QFnest1FinnerEkk) : !fir.ref<i32>232 integer, save :: kk = 1233 print*, 'qq:inner', kk234 end235end236 237! CHECK-LABEL: func @_QPnest2238subroutine nest2239 ! CHECK: fir.call @_QFnest2Pinner()240 call inner241contains242 ! CHECK-LABEL: func private @_QFnest2Pinner243 subroutine inner244 ! CHECK: %[[V_0:[0-9]+]] = fir.address_of(@_QFnest2FinnerEkk) : !fir.ref<i32>245 integer, save :: kk = 77246 print*, 'ss:inner', kk247 end248end249 250! CHECK-LABEL: fir.global internal @_QFfooEpi : f32 {251