brintos

brintos / llvm-project-archived public Read only

0
0
Text · 27.6 KiB · 56c5313 Raw
413 lines · plain
1// Check aliasing with the address *in* (not *of*) a local (fir.alloca) pointer2// variable.3//4// Throughout this test, the ".fir" suffix on symbols indicates a version of the5// MLIR after convert-hlfir-to-fir.  We would like alias analysis results to be6// the same in both versions.7 8// RUN: fir-opt %s -split-input-file -o /dev/null --mlir-disable-threading  \9// RUN:   -pass-pipeline='builtin.module(func.func(test-fir-alias-analysis))' \10// RUN:   2>&1 | FileCheck -match-full-lines %s11 12// subroutine test(n)13//   integer :: n14//   real, pointer :: p0, p115//   real :: arr(n)16//   real, target :: t_arr(n)17//   real, allocatable :: alloc18//   real, allocatable, target :: t_alloc19//   real, target :: t20//   real :: v21// end subroutine test22 23// CHECK-LABEL: Testing : "_QPtest"24 25// The address in a pointer can alias the address in another pointer or the26// address of a target but not the address of other variables.27// CHECK-DAG: p0.tgt#0 <-> p1.tgt#0: MayAlias28// CHECK-DAG: t#0 <-> p0.tgt#0: MayAlias29// CHECK-DAG: t#0 <-> p1.tgt#0: MayAlias30// CHECK-DAG: v#0 <-> p0.tgt#0: NoAlias31// CHECK-DAG: v#0 <-> p1.tgt#0: NoAlias32// CHECK-DAG: p0.tgt.fir#0 <-> p1.tgt.fir#0: MayAlias33// CHECK-DAG: t.fir#0 <-> p0.tgt.fir#0: MayAlias34// CHECK-DAG: t.fir#0 <-> p1.tgt.fir#0: MayAlias35// CHECK-DAG: v.fir#0 <-> p0.tgt.fir#0: NoAlias36// CHECK-DAG: v.fir#0 <-> p1.tgt.fir#0: NoAlias37 38// The address in a pointer cannot alias the address of a pointer.39// CHECK-DAG: p0#0 <-> p0.tgt#0: NoAlias40// CHECK-DAG: p0#0 <-> p1.tgt#0: NoAlias41// CHECK-DAG: p1#0 <-> p0.tgt#0: NoAlias42// CHECK-DAG: p1#0 <-> p1.tgt#0: NoAlias43// CHECK-DAG: p0.fir#0 <-> p0.tgt.fir#0: NoAlias44// CHECK-DAG: p0.fir#0 <-> p1.tgt.fir#0: NoAlias45// CHECK-DAG: p1.fir#0 <-> p0.tgt.fir#0: NoAlias46// CHECK-DAG: p1.fir#0 <-> p1.tgt.fir#0: NoAlias47 48// For some cases, AliasAnalysis analyzes hlfir.designate like fir.box_addr, so49// make sure it doesn't mistakenly see the address of arr(1) as an address that50// was loaded from a pointer and that could alias something.  However, t_arr is51// a target.52// CHECK-DAG: p0.tgt#0 <-> arr(1)#0: NoAlias53// CHECK-DAG: p0.tgt#0 <-> t_arr(1)#0: MayAlias54// CHECK-DAG: p0.tgt.fir#0 <-> arr(1).fir#0: NoAlias55// CHECK-DAG: p0.tgt.fir#0 <-> t_arr(1).fir#0: MayAlias56 57// Like a pointer, an allocatable contains an address, but an allocatable is not58// a pointer and so cannot alias pointers.  However, t_alloc is a target.59// CHECK-DAG: p0.tgt#0 <-> alloc.tgt#0: NoAlias60// CHECK-DAG: p0.tgt#0 <-> t_alloc.tgt#0: MayAlias61// CHECK-DAG: p0.tgt.fir#0 <-> alloc.tgt.fir#0: NoAlias62// CHECK-DAG: p0.tgt.fir#0 <-> t_alloc.tgt.fir#0: MayAlias63 64// The address in an allocatable cannot alias the address of that allocatable.65// CHECK-DAG: alloc#0 <-> alloc.tgt#0: NoAlias66// CHECK-DAG: alloc.fir#0 <-> alloc.tgt.fir#0: NoAlias67 68func.func @_QPtest(%arg0: !fir.ref<i32> {fir.bindc_name = "n"}) {69  %0 = fir.alloca !fir.box<!fir.heap<f32>> {bindc_name = "alloc", uniq_name = "_QFtestEalloc"}70  %1:2 = hlfir.declare %0 {test.ptr="alloc", fortran_attrs = #fir.var_attrs<allocatable>, uniq_name = "_QFtestEalloc"} : (!fir.ref<!fir.box<!fir.heap<f32>>>) -> (!fir.ref<!fir.box<!fir.heap<f32>>>, !fir.ref<!fir.box<!fir.heap<f32>>>)71  %2:2 = hlfir.declare %arg0 {uniq_name = "_QFtestEn"} : (!fir.ref<i32>) -> (!fir.ref<i32>, !fir.ref<i32>)72  %3 = fir.alloca !fir.box<!fir.ptr<f32>> {bindc_name = "p0", uniq_name = "_QFtestEp0"}73  %4:2 = hlfir.declare %3 {test.ptr="p0", fortran_attrs = #fir.var_attrs<pointer>, uniq_name = "_QFtestEp0"} : (!fir.ref<!fir.box<!fir.ptr<f32>>>) -> (!fir.ref<!fir.box<!fir.ptr<f32>>>, !fir.ref<!fir.box<!fir.ptr<f32>>>)74  %5 = fir.alloca !fir.box<!fir.ptr<f32>> {bindc_name = "p1", uniq_name = "_QFtestEp1"}75  %6:2 = hlfir.declare %5 {test.ptr="p1", fortran_attrs = #fir.var_attrs<pointer>, uniq_name = "_QFtestEp1"} : (!fir.ref<!fir.box<!fir.ptr<f32>>>) -> (!fir.ref<!fir.box<!fir.ptr<f32>>>, !fir.ref<!fir.box<!fir.ptr<f32>>>)76  %7 = fir.alloca f32 {bindc_name = "t", fir.target, uniq_name = "_QFtestEt"}77  %8:2 = hlfir.declare %7 {test.ptr="t", fortran_attrs = #fir.var_attrs<target>, uniq_name = "_QFtestEt"} : (!fir.ref<f32>) -> (!fir.ref<f32>, !fir.ref<f32>)78  %9 = fir.alloca !fir.box<!fir.heap<f32>> {bindc_name = "t_alloc", fir.target, uniq_name = "_QFtestEt_alloc"}79  %10:2 = hlfir.declare %9 {fortran_attrs = #fir.var_attrs<allocatable, target>, uniq_name = "_QFtestEt_alloc"} : (!fir.ref<!fir.box<!fir.heap<f32>>>) -> (!fir.ref<!fir.box<!fir.heap<f32>>>, !fir.ref<!fir.box<!fir.heap<f32>>>)80  %11 = fir.alloca f32 {bindc_name = "v", uniq_name = "_QFtestEv"}81  %12:2 = hlfir.declare %11 {test.ptr="v", uniq_name = "_QFtestEv"} : (!fir.ref<f32>) -> (!fir.ref<f32>, !fir.ref<f32>)82  %13 = fir.load %2#0 : !fir.ref<i32>83  %14 = fir.convert %13 : (i32) -> i6484  %15 = fir.convert %14 : (i64) -> index85  %c0 = arith.constant 0 : index86  %16 = arith.cmpi sgt, %15, %c0 : index87  %17 = arith.select %16, %15, %c0 : index88  %18 = fir.alloca !fir.array<?xf32>, %17 {bindc_name = "arr", uniq_name = "_QFtestEarr"}89  %19 = fir.shape %17 : (index) -> !fir.shape<1>90  %20:2 = hlfir.declare %18(%19) {uniq_name = "_QFtestEarr"} : (!fir.ref<!fir.array<?xf32>>, !fir.shape<1>) -> (!fir.box<!fir.array<?xf32>>, !fir.ref<!fir.array<?xf32>>)91  %21 = fir.load %2#0 : !fir.ref<i32>92  %22 = fir.convert %21 : (i32) -> i6493  %23 = fir.convert %22 : (i64) -> index94  %c0_0 = arith.constant 0 : index95  %24 = arith.cmpi sgt, %23, %c0_0 : index96  %25 = arith.select %24, %23, %c0_0 : index97  %26 = fir.alloca !fir.array<?xf32>, %25 {bindc_name = "t_arr", fir.target, uniq_name = "_QFtestEt_arr"}98  %27 = fir.shape %25 : (index) -> !fir.shape<1>99  %28:2 = hlfir.declare %26(%27) {fortran_attrs = #fir.var_attrs<target>, uniq_name = "_QFtestEt_arr"} : (!fir.ref<!fir.array<?xf32>>, !fir.shape<1>) -> (!fir.box<!fir.array<?xf32>>, !fir.ref<!fir.array<?xf32>>)100  %29 = fir.load %4#0 : !fir.ref<!fir.box<!fir.ptr<f32>>>101  %30 = fir.box_addr %29 {test.ptr="p0.tgt"} : (!fir.box<!fir.ptr<f32>>) -> !fir.ptr<f32>102  %31 = fir.load %6#0 : !fir.ref<!fir.box<!fir.ptr<f32>>>103  %32 = fir.box_addr %31 {test.ptr="p1.tgt"} : (!fir.box<!fir.ptr<f32>>) -> !fir.ptr<f32>104  %c1 = arith.constant 1 : index105  %33 = hlfir.designate %20#0 (%c1) {test.ptr="arr(1)"} : (!fir.box<!fir.array<?xf32>>, index) -> !fir.ref<f32>106  %c1_1 = arith.constant 1 : index107  %34 = hlfir.designate %28#0 (%c1_1) {test.ptr="t_arr(1)"} : (!fir.box<!fir.array<?xf32>>, index) -> !fir.ref<f32>108  %35 = fir.load %1#0 : !fir.ref<!fir.box<!fir.heap<f32>>>109  %36 = fir.box_addr %35 {test.ptr="alloc.tgt"} : (!fir.box<!fir.heap<f32>>) -> !fir.heap<f32>110  %37 = fir.load %10#0 : !fir.ref<!fir.box<!fir.heap<f32>>>111  %38 = fir.box_addr %37 {test.ptr="t_alloc.tgt"} : (!fir.box<!fir.heap<f32>>) -> !fir.heap<f32>112  return113}114 115func.func @_QPtest.fir(%arg0: !fir.ref<i32> {fir.bindc_name = "n"}) {116  %0 = fir.alloca !fir.box<!fir.heap<f32>> {bindc_name = "alloc", uniq_name = "_QFtestEalloc"}117  %1 = fir.declare %0 {test.ptr = "alloc.fir", fortran_attrs = #fir.var_attrs<allocatable>, uniq_name = "_QFtestEalloc"} : (!fir.ref<!fir.box<!fir.heap<f32>>>) -> !fir.ref<!fir.box<!fir.heap<f32>>>118  %2 = fir.declare %arg0 {uniq_name = "_QFtestEn"} : (!fir.ref<i32>) -> !fir.ref<i32>119  %3 = fir.alloca !fir.box<!fir.ptr<f32>> {bindc_name = "p0", uniq_name = "_QFtestEp0"}120  %4 = fir.declare %3 {test.ptr = "p0.fir", fortran_attrs = #fir.var_attrs<pointer>, uniq_name = "_QFtestEp0"} : (!fir.ref<!fir.box<!fir.ptr<f32>>>) -> !fir.ref<!fir.box<!fir.ptr<f32>>>121  %5 = fir.alloca !fir.box<!fir.ptr<f32>> {bindc_name = "p1", uniq_name = "_QFtestEp1"}122  %6 = fir.declare %5 {test.ptr = "p1.fir", fortran_attrs = #fir.var_attrs<pointer>, uniq_name = "_QFtestEp1"} : (!fir.ref<!fir.box<!fir.ptr<f32>>>) -> !fir.ref<!fir.box<!fir.ptr<f32>>>123  %7 = fir.alloca f32 {bindc_name = "t", fir.target, uniq_name = "_QFtestEt"}124  %8 = fir.declare %7 {test.ptr = "t.fir", fortran_attrs = #fir.var_attrs<target>, uniq_name = "_QFtestEt"} : (!fir.ref<f32>) -> !fir.ref<f32>125  %9 = fir.alloca !fir.box<!fir.heap<f32>> {bindc_name = "t_alloc", fir.target, uniq_name = "_QFtestEt_alloc"}126  %10 = fir.declare %9 {fortran_attrs = #fir.var_attrs<allocatable, target>, uniq_name = "_QFtestEt_alloc"} : (!fir.ref<!fir.box<!fir.heap<f32>>>) -> !fir.ref<!fir.box<!fir.heap<f32>>>127  %11 = fir.alloca f32 {bindc_name = "v", uniq_name = "_QFtestEv"}128  %12 = fir.declare %11 {test.ptr = "v.fir", uniq_name = "_QFtestEv"} : (!fir.ref<f32>) -> !fir.ref<f32>129  %13 = fir.load %2 : !fir.ref<i32>130  %14 = fir.convert %13 : (i32) -> i64131  %15 = fir.convert %14 : (i64) -> index132  %c0 = arith.constant 0 : index133  %16 = arith.cmpi sgt, %15, %c0 : index134  %17 = arith.select %16, %15, %c0 : index135  %18 = fir.alloca !fir.array<?xf32>, %17 {bindc_name = "arr", uniq_name = "_QFtestEarr"}136  %19 = fir.shape %17 : (index) -> !fir.shape<1>137  %20 = fir.declare %18(%19) {uniq_name = "_QFtestEarr"} : (!fir.ref<!fir.array<?xf32>>, !fir.shape<1>) -> !fir.ref<!fir.array<?xf32>>138  %21 = fir.embox %20(%19) : (!fir.ref<!fir.array<?xf32>>, !fir.shape<1>) -> !fir.box<!fir.array<?xf32>>139  %22 = fir.load %2 : !fir.ref<i32>140  %23 = fir.convert %22 : (i32) -> i64141  %24 = fir.convert %23 : (i64) -> index142  %c0_0 = arith.constant 0 : index143  %25 = arith.cmpi sgt, %24, %c0_0 : index144  %26 = arith.select %25, %24, %c0_0 : index145  %27 = fir.alloca !fir.array<?xf32>, %26 {bindc_name = "t_arr", fir.target, uniq_name = "_QFtestEt_arr"}146  %28 = fir.shape %26 : (index) -> !fir.shape<1>147  %29 = fir.declare %27(%28) {fortran_attrs = #fir.var_attrs<target>, uniq_name = "_QFtestEt_arr"} : (!fir.ref<!fir.array<?xf32>>, !fir.shape<1>) -> !fir.ref<!fir.array<?xf32>>148  %30 = fir.embox %29(%28) : (!fir.ref<!fir.array<?xf32>>, !fir.shape<1>) -> !fir.box<!fir.array<?xf32>>149  %31 = fir.load %4 : !fir.ref<!fir.box<!fir.ptr<f32>>>150  %32 = fir.box_addr %31 {test.ptr = "p0.tgt.fir"} : (!fir.box<!fir.ptr<f32>>) -> !fir.ptr<f32>151  %33 = fir.load %6 : !fir.ref<!fir.box<!fir.ptr<f32>>>152  %34 = fir.box_addr %33 {test.ptr = "p1.tgt.fir"} : (!fir.box<!fir.ptr<f32>>) -> !fir.ptr<f32>153  %c1 = arith.constant 1 : index154  %35 = fir.array_coor %20(%19) %c1 {test.ptr="arr(1).fir"} : (!fir.ref<!fir.array<?xf32>>, !fir.shape<1>, index) -> !fir.ref<f32>155  %c1_1 = arith.constant 1 : index156  %36 = fir.array_coor %29(%28) %c1_1 {test.ptr="t_arr(1).fir"} : (!fir.ref<!fir.array<?xf32>>, !fir.shape<1>, index) -> !fir.ref<f32>157  %37 = fir.load %1 : !fir.ref<!fir.box<!fir.heap<f32>>>158  %38 = fir.box_addr %37 {test.ptr = "alloc.tgt.fir"} : (!fir.box<!fir.heap<f32>>) -> !fir.heap<f32>159  %39 = fir.load %10 : !fir.ref<!fir.box<!fir.heap<f32>>>160  %40 = fir.box_addr %39 {test.ptr = "t_alloc.tgt.fir"} : (!fir.box<!fir.heap<f32>>) -> !fir.heap<f32>161  return162}163 164// -----165 166// Repeat above test except compare the local pointer against dummy args instead167// of other locals.168 169// subroutine test(p1, arr, t_arr, alloc, t_alloc, t, v)170//   real, pointer :: p1171//   real :: arr(:)172//   real, target :: t_arr(:)173//   real, allocatable :: alloc174//   real, allocatable, target :: t_alloc175//   real, target :: t176//   real :: v177//   real, pointer :: p0178// end subroutine test179 180// CHECK-LABEL: Testing : "_QPtest"181 182// The address in a pointer can alias the address in another pointer or the183// address of a target but not the address of other variables.184// CHECK-DAG: p0.tgt#0 <-> p1.tgt#0: MayAlias185// CHECK-DAG: t#0 <-> p0.tgt#0: MayAlias186// CHECK-DAG: t#0 <-> p1.tgt#0: MayAlias187// CHECK-DAG: v#0 <-> p0.tgt#0: NoAlias188// CHECK-DAG: v#0 <-> p1.tgt#0: NoAlias189// CHECK-DAG: p0.tgt.fir#0 <-> p1.tgt.fir#0: MayAlias190// CHECK-DAG: t.fir#0 <-> p0.tgt.fir#0: MayAlias191// CHECK-DAG: t.fir#0 <-> p1.tgt.fir#0: MayAlias192// CHECK-DAG: v.fir#0 <-> p0.tgt.fir#0: NoAlias193// CHECK-DAG: v.fir#0 <-> p1.tgt.fir#0: NoAlias194 195// The address in a pointer cannot alias the address of a pointer.196// CHECK-DAG: p0#0 <-> p0.tgt#0: NoAlias197// CHECK-DAG: p0#0 <-> p1.tgt#0: NoAlias198// CHECK-DAG: p1#0 <-> p0.tgt#0: NoAlias199// CHECK-DAG: p1#0 <-> p1.tgt#0: NoAlias200// CHECK-DAG: p0.fir#0 <-> p0.tgt.fir#0: NoAlias201// CHECK-DAG: p0.fir#0 <-> p1.tgt.fir#0: NoAlias202// CHECK-DAG: p1.fir#0 <-> p0.tgt.fir#0: NoAlias203// CHECK-DAG: p1.fir#0 <-> p1.tgt.fir#0: NoAlias204 205// For some cases, AliasAnalysis analyzes hlfir.designate like fir.box_addr, so206// make sure it doesn't mistakenly see the address of arr(1) as an address that207// was loaded from a pointer and that could alias something.  However, t_arr is208// a target.209// CHECK-DAG: p0.tgt#0 <-> arr(1)#0: NoAlias210// CHECK-DAG: p0.tgt#0 <-> t_arr(1)#0: MayAlias211// CHECK-DAG: p0.tgt.fir#0 <-> arr(1).fir#0: NoAlias212// CHECK-DAG: p0.tgt.fir#0 <-> t_arr(1).fir#0: MayAlias213 214// Like a pointer, an allocatable contains an address, but an allocatable is not215// a pointer and so cannot alias pointers.  However, t_alloc is a target.216// CHECK-DAG: p0.tgt#0 <-> alloc.tgt#0: NoAlias217// CHECK-DAG: p0.tgt#0 <-> t_alloc.tgt#0: MayAlias218// CHECK-DAG: p0.tgt.fir#0 <-> alloc.tgt.fir#0: NoAlias219// CHECK-DAG: p0.tgt.fir#0 <-> t_alloc.tgt.fir#0: MayAlias220 221// The address in an allocatable cannot alias the address of that allocatable.222// CHECK-DAG: alloc#0 <-> alloc.tgt#0: NoAlias223// CHECK-DAG: alloc.fir#0 <-> alloc.tgt.fir#0: NoAlias224 225func.func @_QPtest(%arg0: !fir.ref<!fir.box<!fir.ptr<f32>>> {fir.bindc_name = "p1"}, %arg1: !fir.box<!fir.array<?xf32>> {fir.bindc_name = "arr"}, %arg2: !fir.box<!fir.array<?xf32>> {fir.bindc_name = "t_arr", fir.target}, %arg3: !fir.ref<!fir.box<!fir.heap<f32>>> {fir.bindc_name = "alloc"}, %arg4: !fir.ref<!fir.box<!fir.heap<f32>>> {fir.bindc_name = "t_alloc", fir.target}, %arg5: !fir.ref<f32> {fir.bindc_name = "t", fir.target}, %arg6: !fir.ref<f32> {fir.bindc_name = "v"}) {226  %0 = fir.dummy_scope : !fir.dscope227  %1:2 = hlfir.declare %arg3 dummy_scope %0 {test.ptr="alloc", fortran_attrs = #fir.var_attrs<allocatable>, uniq_name = "_QFtestEalloc"} : (!fir.ref<!fir.box<!fir.heap<f32>>>, !fir.dscope) -> (!fir.ref<!fir.box<!fir.heap<f32>>>, !fir.ref<!fir.box<!fir.heap<f32>>>)228  %2:2 = hlfir.declare %arg1 dummy_scope %0 {uniq_name = "_QFtestEarr"} : (!fir.box<!fir.array<?xf32>>, !fir.dscope) -> (!fir.box<!fir.array<?xf32>>, !fir.box<!fir.array<?xf32>>)229  %3 = fir.alloca !fir.box<!fir.ptr<f32>> {bindc_name = "p0", uniq_name = "_QFtestEp0"}230  %4:2 = hlfir.declare %3 {test.ptr="p0", fortran_attrs = #fir.var_attrs<pointer>, uniq_name = "_QFtestEp0"} : (!fir.ref<!fir.box<!fir.ptr<f32>>>) -> (!fir.ref<!fir.box<!fir.ptr<f32>>>, !fir.ref<!fir.box<!fir.ptr<f32>>>)231  %5:2 = hlfir.declare %arg0 dummy_scope %0 {test.ptr="p1", fortran_attrs = #fir.var_attrs<pointer>, uniq_name = "_QFtestEp1"} : (!fir.ref<!fir.box<!fir.ptr<f32>>>, !fir.dscope) -> (!fir.ref<!fir.box<!fir.ptr<f32>>>, !fir.ref<!fir.box<!fir.ptr<f32>>>)232  %6:2 = hlfir.declare %arg5 dummy_scope %0 {test.ptr="t", fortran_attrs = #fir.var_attrs<target>, uniq_name = "_QFtestEt"} : (!fir.ref<f32>, !fir.dscope) -> (!fir.ref<f32>, !fir.ref<f32>)233  %7:2 = hlfir.declare %arg4 dummy_scope %0 {fortran_attrs = #fir.var_attrs<allocatable, target>, uniq_name = "_QFtestEt_alloc"} : (!fir.ref<!fir.box<!fir.heap<f32>>>, !fir.dscope) -> (!fir.ref<!fir.box<!fir.heap<f32>>>, !fir.ref<!fir.box<!fir.heap<f32>>>)234  %8:2 = hlfir.declare %arg2 dummy_scope %0 {fortran_attrs = #fir.var_attrs<target>, uniq_name = "_QFtestEt_arr"} : (!fir.box<!fir.array<?xf32>>, !fir.dscope) -> (!fir.box<!fir.array<?xf32>>, !fir.box<!fir.array<?xf32>>)235  %9:2 = hlfir.declare %arg6 dummy_scope %0 {test.ptr="v", uniq_name = "_QFtestEv"} : (!fir.ref<f32>, !fir.dscope) -> (!fir.ref<f32>, !fir.ref<f32>)236  %10 = fir.load %4#0 : !fir.ref<!fir.box<!fir.ptr<f32>>>237  %11 = fir.box_addr %10 {test.ptr="p0.tgt"} : (!fir.box<!fir.ptr<f32>>) -> !fir.ptr<f32>238  %12 = fir.load %5#0 : !fir.ref<!fir.box<!fir.ptr<f32>>>239  %13 = fir.box_addr %12 {test.ptr="p1.tgt"}  : (!fir.box<!fir.ptr<f32>>) -> !fir.ptr<f32>240  %c1 = arith.constant 1 : index241  %14 = hlfir.designate %2#0 (%c1) {test.ptr="arr(1)"} : (!fir.box<!fir.array<?xf32>>, index) -> !fir.ref<f32>242  %c1_0 = arith.constant 1 : index243  %15 = hlfir.designate %8#0 (%c1_0) {test.ptr="t_arr(1)"} : (!fir.box<!fir.array<?xf32>>, index) -> !fir.ref<f32>244  %16 = fir.load %1#0 : !fir.ref<!fir.box<!fir.heap<f32>>>245  %17 = fir.box_addr %16 {test.ptr="alloc.tgt"} : (!fir.box<!fir.heap<f32>>) -> !fir.heap<f32>246  %18 = fir.load %7#0 : !fir.ref<!fir.box<!fir.heap<f32>>>247  %19 = fir.box_addr %18 {test.ptr="t_alloc.tgt"} : (!fir.box<!fir.heap<f32>>) -> !fir.heap<f32>248  return249}250 251func.func @_QPtest.fir(%arg0: !fir.ref<!fir.box<!fir.ptr<f32>>> {fir.bindc_name = "p1"}, %arg1: !fir.box<!fir.array<?xf32>> {fir.bindc_name = "arr"}, %arg2: !fir.box<!fir.array<?xf32>> {fir.bindc_name = "t_arr", fir.target}, %arg3: !fir.ref<!fir.box<!fir.heap<f32>>> {fir.bindc_name = "alloc"}, %arg4: !fir.ref<!fir.box<!fir.heap<f32>>> {fir.bindc_name = "t_alloc", fir.target}, %arg5: !fir.ref<f32> {fir.bindc_name = "t", fir.target}, %arg6: !fir.ref<f32> {fir.bindc_name = "v"}) {252  %0 = fir.dummy_scope : !fir.dscope253  %1 = fir.declare %arg3 dummy_scope %0 {test.ptr = "alloc.fir", fortran_attrs = #fir.var_attrs<allocatable>, uniq_name = "_QFtestEalloc"} : (!fir.ref<!fir.box<!fir.heap<f32>>>, !fir.dscope) -> !fir.ref<!fir.box<!fir.heap<f32>>>254  %2 = fir.declare %arg1 dummy_scope %0 {uniq_name = "_QFtestEarr"} : (!fir.box<!fir.array<?xf32>>, !fir.dscope) -> !fir.box<!fir.array<?xf32>>255  %3 = fir.rebox %2 : (!fir.box<!fir.array<?xf32>>) -> !fir.box<!fir.array<?xf32>>256  %4 = fir.alloca !fir.box<!fir.ptr<f32>> {bindc_name = "p0", uniq_name = "_QFtestEp0"}257  %5 = fir.declare %4 {test.ptr = "p0.fir", fortran_attrs = #fir.var_attrs<pointer>, uniq_name = "_QFtestEp0"} : (!fir.ref<!fir.box<!fir.ptr<f32>>>) -> !fir.ref<!fir.box<!fir.ptr<f32>>>258  %6 = fir.declare %arg0 dummy_scope %0 {test.ptr = "p1.fir", fortran_attrs = #fir.var_attrs<pointer>, uniq_name = "_QFtestEp1"} : (!fir.ref<!fir.box<!fir.ptr<f32>>>, !fir.dscope) -> !fir.ref<!fir.box<!fir.ptr<f32>>>259  %7 = fir.declare %arg5 dummy_scope %0 {test.ptr = "t.fir", fortran_attrs = #fir.var_attrs<target>, uniq_name = "_QFtestEt"} : (!fir.ref<f32>, !fir.dscope) -> !fir.ref<f32>260  %8 = fir.declare %arg4 dummy_scope %0 {fortran_attrs = #fir.var_attrs<allocatable, target>, uniq_name = "_QFtestEt_alloc"} : (!fir.ref<!fir.box<!fir.heap<f32>>>, !fir.dscope) -> !fir.ref<!fir.box<!fir.heap<f32>>>261  %9 = fir.declare %arg2 dummy_scope %0 {fortran_attrs = #fir.var_attrs<target>, uniq_name = "_QFtestEt_arr"} : (!fir.box<!fir.array<?xf32>>, !fir.dscope) -> !fir.box<!fir.array<?xf32>>262  %10 = fir.rebox %9 : (!fir.box<!fir.array<?xf32>>) -> !fir.box<!fir.array<?xf32>>263  %11 = fir.declare %arg6 dummy_scope %0 {test.ptr = "v.fir", uniq_name = "_QFtestEv"} : (!fir.ref<f32>, !fir.dscope) -> !fir.ref<f32>264  %12 = fir.load %5 : !fir.ref<!fir.box<!fir.ptr<f32>>>265  %13 = fir.box_addr %12 {test.ptr = "p0.tgt.fir"} : (!fir.box<!fir.ptr<f32>>) -> !fir.ptr<f32>266  %14 = fir.load %6 : !fir.ref<!fir.box<!fir.ptr<f32>>>267  %15 = fir.box_addr %14 {test.ptr = "p1.tgt.fir"} : (!fir.box<!fir.ptr<f32>>) -> !fir.ptr<f32>268  %c1 = arith.constant 1 : index269  %16 = fir.array_coor %3 %c1 {test.ptr="arr(1).fir"} : (!fir.box<!fir.array<?xf32>>, index) -> !fir.ref<f32>270  %c1_0 = arith.constant 1 : index271  %17 = fir.array_coor %10 %c1_0 {test.ptr="t_arr(1).fir"} : (!fir.box<!fir.array<?xf32>>, index) -> !fir.ref<f32>272  %18 = fir.load %1 : !fir.ref<!fir.box<!fir.heap<f32>>>273  %19 = fir.box_addr %18 {test.ptr = "alloc.tgt.fir"} : (!fir.box<!fir.heap<f32>>) -> !fir.heap<f32>274  %20 = fir.load %8 : !fir.ref<!fir.box<!fir.heap<f32>>>275  %21 = fir.box_addr %20 {test.ptr = "t_alloc.tgt.fir"} : (!fir.box<!fir.heap<f32>>) -> !fir.heap<f32>276  return277}278 279// -----280 281// Repeat above test except compare the local pointer against globals.282 283// module m284//   real, pointer :: p1285//   real :: arr(2)286//   real, target :: t_arr(2)287//   real, allocatable :: alloc288//   real, allocatable, target :: t_alloc289//   real, target :: t290//   real :: v291// contains292//   subroutine test()293//     real, pointer :: p0294//   end subroutine test295// end module m296 297// CHECK-LABEL: Testing : "_QMmPtest"298 299// The address in a pointer can alias the address in another pointer or the300// address of a target but not the address of other variables.301// CHECK-DAG: p0.tgt#0 <-> p1.tgt#0: MayAlias302// CHECK-DAG: t#0 <-> p0.tgt#0: MayAlias303// CHECK-DAG: t#0 <-> p1.tgt#0: MayAlias304// CHECK-DAG: v#0 <-> p0.tgt#0: NoAlias305// CHECK-DAG: v#0 <-> p1.tgt#0: NoAlias306// CHECK-DAG: p0.tgt.fir#0 <-> p1.tgt.fir#0: MayAlias307// CHECK-DAG: t.fir#0 <-> p0.tgt.fir#0: MayAlias308// CHECK-DAG: t.fir#0 <-> p1.tgt.fir#0: MayAlias309// CHECK-DAG: v.fir#0 <-> p0.tgt.fir#0: NoAlias310// CHECK-DAG: v.fir#0 <-> p1.tgt.fir#0: NoAlias311 312// The address in a pointer cannot alias the address of a pointer.313// CHECK-DAG: p0#0 <-> p0.tgt#0: NoAlias314// CHECK-DAG: p0#0 <-> p1.tgt#0: NoAlias315// CHECK-DAG: p1#0 <-> p0.tgt#0: NoAlias316// CHECK-DAG: p1#0 <-> p1.tgt#0: NoAlias317// CHECK-DAG: p0.fir#0 <-> p0.tgt.fir#0: NoAlias318// CHECK-DAG: p0.fir#0 <-> p1.tgt.fir#0: NoAlias319// CHECK-DAG: p1.fir#0 <-> p0.tgt.fir#0: NoAlias320// CHECK-DAG: p1.fir#0 <-> p1.tgt.fir#0: NoAlias321 322// For some cases, AliasAnalysis analyzes hlfir.designate like fir.box_addr, so323// make sure it doesn't mistakenly see the address of arr(1) as an address that324// was loaded from a pointer and that could alias something.  However, t_arr is325// a target.326// CHECK-DAG: p0.tgt#0 <-> arr(1)#0: NoAlias327// CHECK-DAG: p0.tgt#0 <-> t_arr(1)#0: MayAlias328// CHECK-DAG: p0.tgt.fir#0 <-> arr(1).fir#0: NoAlias329// CHECK-DAG: p0.tgt.fir#0 <-> t_arr(1).fir#0: MayAlias330 331// Like a pointer, an allocatable contains an address, but an allocatable is not332// a pointer and so cannot alias pointers.  However, t_alloc is a target.333// CHECK-DAG: p0.tgt#0 <-> alloc.tgt#0: NoAlias334// CHECK-DAG: p0.tgt#0 <-> t_alloc.tgt#0: MayAlias335// CHECK-DAG: p0.tgt.fir#0 <-> alloc.tgt.fir#0: NoAlias336// CHECK-DAG: p0.tgt.fir#0 <-> t_alloc.tgt.fir#0: MayAlias337 338// The address in an allocatable cannot alias the address of that allocatable.339// CHECK-DAG: alloc#0 <-> alloc.tgt#0: NoAlias340// CHECK-DAG: alloc.fir#0 <-> alloc.tgt.fir#0: NoAlias341 342func.func @_QMmPtest() {343  %0 = fir.address_of(@_QMmEalloc) : !fir.ref<!fir.box<!fir.heap<f32>>>344  %1:2 = hlfir.declare %0 {test.ptr="alloc", fortran_attrs = #fir.var_attrs<allocatable>, uniq_name = "_QMmEalloc"} : (!fir.ref<!fir.box<!fir.heap<f32>>>) -> (!fir.ref<!fir.box<!fir.heap<f32>>>, !fir.ref<!fir.box<!fir.heap<f32>>>)345  %2 = fir.address_of(@_QMmEarr) : !fir.ref<!fir.array<2xf32>>346  %c2 = arith.constant 2 : index347  %3 = fir.shape %c2 : (index) -> !fir.shape<1>348  %4:2 = hlfir.declare %2(%3) {uniq_name = "_QMmEarr"} : (!fir.ref<!fir.array<2xf32>>, !fir.shape<1>) -> (!fir.ref<!fir.array<2xf32>>, !fir.ref<!fir.array<2xf32>>)349  %5 = fir.address_of(@_QMmEp1) : !fir.ref<!fir.box<!fir.ptr<f32>>>350  %6:2 = hlfir.declare %5 {test.ptr="p1", fortran_attrs = #fir.var_attrs<pointer>, uniq_name = "_QMmEp1"} : (!fir.ref<!fir.box<!fir.ptr<f32>>>) -> (!fir.ref<!fir.box<!fir.ptr<f32>>>, !fir.ref<!fir.box<!fir.ptr<f32>>>)351  %7 = fir.address_of(@_QMmEt) : !fir.ref<f32>352  %8:2 = hlfir.declare %7 {test.ptr="t", fortran_attrs = #fir.var_attrs<target>, uniq_name = "_QMmEt"} : (!fir.ref<f32>) -> (!fir.ref<f32>, !fir.ref<f32>)353  %9 = fir.address_of(@_QMmEt_alloc) : !fir.ref<!fir.box<!fir.heap<f32>>>354  %10:2 = hlfir.declare %9 {fortran_attrs = #fir.var_attrs<allocatable, target>, uniq_name = "_QMmEt_alloc"} : (!fir.ref<!fir.box<!fir.heap<f32>>>) -> (!fir.ref<!fir.box<!fir.heap<f32>>>, !fir.ref<!fir.box<!fir.heap<f32>>>)355  %11 = fir.address_of(@_QMmEt_arr) : !fir.ref<!fir.array<2xf32>>356  %c2_0 = arith.constant 2 : index357  %12 = fir.shape %c2_0 : (index) -> !fir.shape<1>358  %13:2 = hlfir.declare %11(%12) {fortran_attrs = #fir.var_attrs<target>, uniq_name = "_QMmEt_arr"} : (!fir.ref<!fir.array<2xf32>>, !fir.shape<1>) -> (!fir.ref<!fir.array<2xf32>>, !fir.ref<!fir.array<2xf32>>)359  %14 = fir.address_of(@_QMmEv) : !fir.ref<f32>360  %15:2 = hlfir.declare %14 {test.ptr="v", uniq_name = "_QMmEv"} : (!fir.ref<f32>) -> (!fir.ref<f32>, !fir.ref<f32>)361  %16 = fir.alloca !fir.box<!fir.ptr<f32>> {bindc_name = "p0", uniq_name = "_QMmFtestEp0"}362  %17:2 = hlfir.declare %16 {test.ptr="p0", fortran_attrs = #fir.var_attrs<pointer>, uniq_name = "_QMmFtestEp0"} : (!fir.ref<!fir.box<!fir.ptr<f32>>>) -> (!fir.ref<!fir.box<!fir.ptr<f32>>>, !fir.ref<!fir.box<!fir.ptr<f32>>>)363  %18 = fir.load %17#0 : !fir.ref<!fir.box<!fir.ptr<f32>>>364  %19 = fir.box_addr %18 {test.ptr="p0.tgt"} : (!fir.box<!fir.ptr<f32>>) -> !fir.ptr<f32>365  %20 = fir.load %6#0 : !fir.ref<!fir.box<!fir.ptr<f32>>>366  %21 = fir.box_addr %20 {test.ptr="p1.tgt"}  : (!fir.box<!fir.ptr<f32>>) -> !fir.ptr<f32>367  %c1 = arith.constant 1 : index368  %22 = hlfir.designate %4#0 (%c1) {test.ptr="arr(1)"} : (!fir.ref<!fir.array<2xf32>>, index) -> !fir.ref<f32>369  %c1_1 = arith.constant 1 : index370  %23 = hlfir.designate %13#0 (%c1_1) {test.ptr="t_arr(1)"} : (!fir.ref<!fir.array<2xf32>>, index) -> !fir.ref<f32>371  %24 = fir.load %1#0 : !fir.ref<!fir.box<!fir.heap<f32>>>372  %25 = fir.box_addr %24 {test.ptr="alloc.tgt"} : (!fir.box<!fir.heap<f32>>) -> !fir.heap<f32>373  %26 = fir.load %10#0 : !fir.ref<!fir.box<!fir.heap<f32>>>374  %27 = fir.box_addr %26 {test.ptr="t_alloc.tgt"} : (!fir.box<!fir.heap<f32>>) -> !fir.heap<f32>375  return376}377 378func.func @_QMmPtest.fir() {379  %0 = fir.address_of(@_QMmEalloc) : !fir.ref<!fir.box<!fir.heap<f32>>>380  %1 = fir.declare %0 {test.ptr = "alloc.fir", fortran_attrs = #fir.var_attrs<allocatable>, uniq_name = "_QMmEalloc"} : (!fir.ref<!fir.box<!fir.heap<f32>>>) -> !fir.ref<!fir.box<!fir.heap<f32>>>381  %2 = fir.address_of(@_QMmEarr) : !fir.ref<!fir.array<2xf32>>382  %c2 = arith.constant 2 : index383  %3 = fir.shape %c2 : (index) -> !fir.shape<1>384  %4 = fir.declare %2(%3) {uniq_name = "_QMmEarr"} : (!fir.ref<!fir.array<2xf32>>, !fir.shape<1>) -> !fir.ref<!fir.array<2xf32>>385  %5 = fir.address_of(@_QMmEp1) : !fir.ref<!fir.box<!fir.ptr<f32>>>386  %6 = fir.declare %5 {test.ptr = "p1.fir", fortran_attrs = #fir.var_attrs<pointer>, uniq_name = "_QMmEp1"} : (!fir.ref<!fir.box<!fir.ptr<f32>>>) -> !fir.ref<!fir.box<!fir.ptr<f32>>>387  %7 = fir.address_of(@_QMmEt) : !fir.ref<f32>388  %8 = fir.declare %7 {test.ptr = "t.fir", fortran_attrs = #fir.var_attrs<target>, uniq_name = "_QMmEt"} : (!fir.ref<f32>) -> !fir.ref<f32>389  %9 = fir.address_of(@_QMmEt_alloc) : !fir.ref<!fir.box<!fir.heap<f32>>>390  %10 = fir.declare %9 {fortran_attrs = #fir.var_attrs<allocatable, target>, uniq_name = "_QMmEt_alloc"} : (!fir.ref<!fir.box<!fir.heap<f32>>>) -> !fir.ref<!fir.box<!fir.heap<f32>>>391  %11 = fir.address_of(@_QMmEt_arr) : !fir.ref<!fir.array<2xf32>>392  %c2_0 = arith.constant 2 : index393  %12 = fir.shape %c2_0 : (index) -> !fir.shape<1>394  %13 = fir.declare %11(%12) {fortran_attrs = #fir.var_attrs<target>, uniq_name = "_QMmEt_arr"} : (!fir.ref<!fir.array<2xf32>>, !fir.shape<1>) -> !fir.ref<!fir.array<2xf32>>395  %14 = fir.address_of(@_QMmEv) : !fir.ref<f32>396  %15 = fir.declare %14 {test.ptr = "v.fir", uniq_name = "_QMmEv"} : (!fir.ref<f32>) -> !fir.ref<f32>397  %16 = fir.alloca !fir.box<!fir.ptr<f32>> {bindc_name = "p0", uniq_name = "_QMmFtestEp0"}398  %17 = fir.declare %16 {test.ptr = "p0.fir", fortran_attrs = #fir.var_attrs<pointer>, uniq_name = "_QMmFtestEp0"} : (!fir.ref<!fir.box<!fir.ptr<f32>>>) -> !fir.ref<!fir.box<!fir.ptr<f32>>>399  %18 = fir.load %17 : !fir.ref<!fir.box<!fir.ptr<f32>>>400  %19 = fir.box_addr %18 {test.ptr = "p0.tgt.fir"} : (!fir.box<!fir.ptr<f32>>) -> !fir.ptr<f32>401  %20 = fir.load %6 : !fir.ref<!fir.box<!fir.ptr<f32>>>402  %21 = fir.box_addr %20 {test.ptr = "p1.tgt.fir"} : (!fir.box<!fir.ptr<f32>>) -> !fir.ptr<f32>403  %c1 = arith.constant 1 : index404  %22 = fir.array_coor %4(%3) %c1 {test.ptr="arr(1).fir"} : (!fir.ref<!fir.array<2xf32>>, !fir.shape<1>, index) -> !fir.ref<f32>405  %c1_1 = arith.constant 1 : index406  %23 = fir.array_coor %13(%12) %c1_1 {test.ptr="t_arr(1).fir"} : (!fir.ref<!fir.array<2xf32>>, !fir.shape<1>, index) -> !fir.ref<f32>407  %24 = fir.load %1 : !fir.ref<!fir.box<!fir.heap<f32>>>408  %25 = fir.box_addr %24 {test.ptr = "alloc.tgt.fir"} : (!fir.box<!fir.heap<f32>>) -> !fir.heap<f32>409  %26 = fir.load %10 : !fir.ref<!fir.box<!fir.heap<f32>>>410  %27 = fir.box_addr %26 {test.ptr = "t_alloc.tgt.fir"} : (!fir.box<!fir.heap<f32>>) -> !fir.heap<f32>411  return412}413