! RUN: bbc -emit-fir -o - %s | FileCheck %s ! Check more advanced equivalence cases ! Several set of local and global equivalences in the same scope ! CHECK-LABEL: @_QPtest_eq_sets subroutine test_eq_sets DIMENSION Al(4), Bl(4) EQUIVALENCE (Al(1), Bl(2)) ! CHECK-DAG: %[[albl:.*]] = fir.alloca !fir.array<20xi8> ! CHECK-DAG: %[[alAddr:.*]] = fir.coordinate_of %[[albl]], %c4{{.*}} : (!fir.ref>, index) -> !fir.ref ! CHECK-DAG: %[[al:.*]] = fir.convert %[[alAddr]] : (!fir.ref) -> !fir.ptr> ! CHECK-DAG: %[[blAddr:.*]] = fir.coordinate_of %[[albl]], %c0{{.*}} : (!fir.ref>, index) -> !fir.ref ! CHECK-DAG: %[[bl:.*]] = fir.convert %[[blAddr]] : (!fir.ref) -> !fir.ptr> DIMENSION Il(2), Xl(2) EQUIVALENCE (Il(2), Xl(1)) ! CHECK-DAG: %[[ilxl:.*]] = fir.alloca !fir.array<12xi8> ! CHECK-DAG: %[[ilAddr:.*]] = fir.coordinate_of %[[ilxl]], %c0{{.*}} : (!fir.ref>, index) -> !fir.ref ! CHECK-DAG: %[[il:.*]] = fir.convert %[[ilAddr]] : (!fir.ref) -> !fir.ptr> ! CHECK-DAG: %[[xlAddr:.*]] = fir.coordinate_of %[[ilxl]], %c4{{.*}} : (!fir.ref>, index) -> !fir.ref ! CHECK-DAG: %[[xl:.*]] = fir.convert %[[xlAddr]] : (!fir.ref) -> !fir.ptr> DIMENSION Ag(2), Bg(2) SAVE Ag, Bg EQUIVALENCE (Ag(1), Bg(2)) ! CHECK-DAG: %[[agbg:.*]] = fir.address_of(@_QFtest_eq_setsEag) : !fir.ref> ! CHECK-DAG: %[[agAddr:.*]] = fir.coordinate_of %[[agbg]], %c4{{.*}} : (!fir.ref>, index) -> !fir.ref ! CHECK-DAG: %[[ag:.*]] = fir.convert %[[agAddr]] : (!fir.ref) -> !fir.ptr> ! CHECK-DAG: %[[bgAddr:.*]] = fir.coordinate_of %[[agbg]], %c0{{.*}} : (!fir.ref>, index) -> !fir.ref ! CHECK-DAG: %[[bg:.*]] = fir.convert %[[bgAddr]] : (!fir.ref) -> !fir.ptr> DIMENSION Ig(2), Xg(2) SAVE Ig, Xg EQUIVALENCE (Ig(1), Xg(1)) ! CHECK-DAG: %[[igxg:.*]] = fir.address_of(@_QFtest_eq_setsEig) : !fir.ref> ! CHECK-DAG: %[[igOffset:.*]] = arith.constant 0 : index ! CHECK-DAG: %[[igAddr:.*]] = fir.coordinate_of %[[igxg]], %c0{{.*}} : (!fir.ref>, index) -> !fir.ref ! CHECK-DAG: %[[ig:.*]] = fir.convert %[[igAddr]] : (!fir.ref) -> !fir.ptr> ! CHECK-DAG: %[[xgAddr:.*]] = fir.coordinate_of %[[igxg]], %c0{{.*}} : (!fir.ref>, index) -> !fir.ref ! CHECK-DAG: %[[xg:.*]] = fir.convert %[[xgAddr]] : (!fir.ref) -> !fir.ptr> ! CHECK: %[[alCast:.*]] = fir.convert %[[al]] : (!fir.ptr>) -> !fir.ref> ! CHECK: %[[blCast:.*]] = fir.convert %[[bl]] : (!fir.ptr>) -> !fir.ref> ! CHECK: %[[ilCast:.*]] = fir.convert %[[il]] : (!fir.ptr>) -> !fir.ref> ! CHECK: %[[xlCast:.*]] = fir.convert %[[xl]] : (!fir.ptr>) -> !fir.ref> ! CHECK: %[[agCast:.*]] = fir.convert %[[ag]] : (!fir.ptr>) -> !fir.ref> ! CHECK: %[[bgCast:.*]] = fir.convert %[[bg]] : (!fir.ptr>) -> !fir.ref> ! CHECK: %[[xgCast:.*]] = fir.convert %[[xg]] : (!fir.ptr>) -> !fir.ref> ! CHECK: %[[igCast:.*]] = fir.convert %[[ig]] : (!fir.ptr>) -> !fir.ref> call fooc(Al, Bl, Il, Xl, Ag, Bg, Xg, Ig) ! CHECK: fir.call @_QPfooc(%[[alCast]], %[[blCast]], %[[ilCast]], %[[xlCast]], %[[agCast]], %[[bgCast]], %[[xgCast]], %[[igCast]]) end subroutine ! Mixing global equivalence and entry ! CHECK-LABEL: @_QPeq_and_entry_foo() subroutine eq_and_entry_foo SAVE x, i DIMENSION :: x(2) EQUIVALENCE (x(2), i) call foo1(x, i) ! CHECK: %[[xi:.*]] = fir.address_of(@_QFeq_and_entry_fooEi) : !fir.ref> ! CHECK-DAG: %[[iOffset:.*]] = arith.constant 4 : index ! CHECK-DAG: %[[iAddr:.*]] = fir.coordinate_of %[[xi]], %[[iOffset]] : (!fir.ref>, index) -> !fir.ref ! CHECK-DAG: %[[i:.*]] = fir.convert %[[iAddr]] : (!fir.ref) -> !fir.ptr ! CHECK-DAG: %[[xOffset:.*]] = arith.constant 0 : index ! CHECK-DAG: %[[xAddr:.*]] = fir.coordinate_of %[[xi]], %[[xOffset]] : (!fir.ref>, index) -> !fir.ref ! CHECK-DAG: %[[x:.*]] = fir.convert %[[xAddr]] : (!fir.ref) -> !fir.ptr> call foo2(x, i) ! CHECK: %[[xCast:.*]] = fir.convert %[[x]] : (!fir.ptr>) -> !fir.ref> ! CHECK: %[[iCast:.*]] = fir.convert %[[i]] : (!fir.ptr) -> !fir.ref ! CHECK: fir.call @_QPfoo1(%[[xCast]], %[[iCast]]) : (!fir.ref>, !fir.ref) -> () entry eq_and_entry_bar call foo2(x, i) ! CHECK: %[[xCast2:.*]] = fir.convert %[[x]] : (!fir.ptr>) -> !fir.ref> ! CHECK: %[[iCast2:.*]] = fir.convert %[[i]] : (!fir.ptr) -> !fir.ref ! CHECK: fir.call @_QPfoo2(%[[xCast2]], %[[iCast2]]) : (!fir.ref>, !fir.ref) -> () end ! CHECK-LABEL: @_QPeq_and_entry_bar() ! CHECK: %[[xi:.*]] = fir.address_of(@_QFeq_and_entry_fooEi) : !fir.ref> ! CHECK-DAG: %[[iOffset:.*]] = arith.constant 4 : index ! CHECK-DAG: %[[iAddr:.*]] = fir.coordinate_of %[[xi]], %[[iOffset]] : (!fir.ref>, index) -> !fir.ref ! CHECK-DAG: %[[i:.*]] = fir.convert %[[iAddr]] : (!fir.ref) -> !fir.ptr ! CHECK-DAG: %[[xOffset:.*]] = arith.constant 0 : index ! CHECK-DAG: %[[xAddr:.*]] = fir.coordinate_of %[[xi]], %[[xOffset]] : (!fir.ref>, index) -> !fir.ref ! CHECK-DAG: %[[x:.*]] = fir.convert %[[xAddr]] : (!fir.ref) -> !fir.ptr> ! CHECK-NOT: fir.call @_QPfoo1 ! CHECK: %[[xCast:.*]] = fir.convert %[[x]] : (!fir.ptr>) -> !fir.ref> ! CHECK: %[[iCast:.*]] = fir.convert %[[i]] : (!fir.ptr) -> !fir.ref ! CHECK: fir.call @_QPfoo2(%[[xCast]], %[[iCast]]) : (!fir.ref>, !fir.ref) -> ()