// Use --mlir-disable-threading so that the AA queries are serialized // as well as its diagnostic output. // RUN: fir-opt %s -pass-pipeline='builtin.module(func.func(test-fir-alias-analysis))' -split-input-file --mlir-disable-threading 2>&1 | FileCheck %s // module m // type t // real, pointer :: pointer_component // end type t // type(t) :: a // contains // subroutine test(pointer_dummy, x) // real, pointer :: pointer_dummy // real, target :: x // pointer_dummy => x // call test2(a%pointer_component) // end subroutine test // end module m // A composite with a pointer component may alias with a dummy pointer // CHECK-LABEL: Testing : "_QMmPtest // CHECK: a#0 <-> func.region0#0: MayAlias // FIXME: a's box cannot alias with raw reference to f32 (x), so MayAlias below must be NoAlias: // CHECK: a#0 <-> func.region0#1: MayAlias // FIXME: pointer_dummy's box cannot alias with raw reference to f32 (x), so MayAlias below must be NoAlias: // CHECK: func.region0#0 <-> func.region0#1: MayAlias fir.global @_QMmEa : !fir.type<_QMmTt{pointer_component:!fir.box>}> { %0 = fir.undefined !fir.type<_QMmTt{pointer_component:!fir.box>}> fir.has_value %0 : !fir.type<_QMmTt{pointer_component:!fir.box>}> } func.func @_QMmPtest(%arg0: !fir.ref>> {fir.bindc_name = "pointer_dummy"}, %arg1: !fir.ref {fir.bindc_name = "x", fir.target}) attributes {test.ptr = "func"} { %0 = fir.address_of(@_QMmEa) {test.ptr = "a"} : !fir.ref>}>> %1 = fir.embox %arg1 : (!fir.ref) -> !fir.box> fir.store %1 to %arg0 : !fir.ref>> %2 = fir.field_index pointer_component, !fir.type<_QMmTt{pointer_component:!fir.box>}> %3 = fir.coordinate_of %0, %2 : (!fir.ref>}>>, !fir.field) -> !fir.ref>> %4 = fir.load %3 : !fir.ref>> %5 = fir.box_addr %4 : (!fir.box>) -> !fir.ptr %6 = fir.convert %5 : (!fir.ptr) -> !fir.ref fir.call @_QPtest2(%6) fastmath : (!fir.ref) -> () return } func.func private @_QPtest2(!fir.ref) // ----- // A composite with a pointer component may alias with a dummy // argument of composite type with a pointer component: // module m // type t // real, pointer :: pointer_component // end type t // type(t) :: a // contains // subroutine test(b, x) // type(t) :: b // real, target :: x // a%pointer_component => x // call test2(b%pointer_component) // end subroutine test // end module m // CHECK-LABEL: Testing : "_QMmPtest" // CHECK: a#0 <-> func.region0#0: MayAlias fir.global @_QMmEa : !fir.type<_QMmTt{pointer_component:!fir.box>}> { %0 = fir.undefined !fir.type<_QMmTt{pointer_component:!fir.box>}> fir.has_value %0 : !fir.type<_QMmTt{pointer_component:!fir.box>}> } func.func @_QMmPtest(%arg0: !fir.ref>}>> {fir.bindc_name = "b"}, %arg1: !fir.ref {fir.bindc_name = "x", fir.target}) attributes {test.ptr = "func"} { %0 = fir.address_of(@_QMmEa) {test.ptr = "a"} : !fir.ref>}>> %1 = fir.field_index pointer_component, !fir.type<_QMmTt{pointer_component:!fir.box>}> %2 = fir.coordinate_of %0, %1 : (!fir.ref>}>>, !fir.field) -> !fir.ref>> %3 = fir.embox %arg1 : (!fir.ref) -> !fir.box> fir.store %3 to %2 : !fir.ref>> %4 = fir.field_index pointer_component, !fir.type<_QMmTt{pointer_component:!fir.box>}> %5 = fir.coordinate_of %arg0, %4 : (!fir.ref>}>>, !fir.field) -> !fir.ref>> %6 = fir.load %5 : !fir.ref>> %7 = fir.box_addr %6 : (!fir.box>) -> !fir.ptr %8 = fir.convert %7 : (!fir.ptr) -> !fir.ref fir.call @_QPtest2(%8) fastmath : (!fir.ref) -> () return } func.func private @_QPtest2(!fir.ref) // ----- // Two dummy arguments of composite type with a pointer component // may alias each other: // module m // type t // real, pointer :: pointer_component // end type t // contains // subroutine test(a, b, x) // type(t) :: a, b // real, target :: x // a%pointer_component => x // call test2(b%pointer_component) // end subroutine test // end module m // CHECK-LABEL: Testing : "_QMmPtest" // CHECK: func.region0#0 <-> func.region0#1: MayAlias func.func @_QMmPtest(%arg0: !fir.ref>}>> {fir.bindc_name = "a"}, %arg1: !fir.ref>}>> {fir.bindc_name = "b"}, %arg2: !fir.ref {fir.bindc_name = "x", fir.target}) attributes {test.ptr = "func"} { %0 = fir.field_index pointer_component, !fir.type<_QMmTt{pointer_component:!fir.box>}> %1 = fir.coordinate_of %arg0, %0 : (!fir.ref>}>>, !fir.field) -> !fir.ref>> %2 = fir.embox %arg2 : (!fir.ref) -> !fir.box> fir.store %2 to %1 : !fir.ref>> %3 = fir.field_index pointer_component, !fir.type<_QMmTt{pointer_component:!fir.box>}> %4 = fir.coordinate_of %arg1, %3 : (!fir.ref>}>>, !fir.field) -> !fir.ref>> %5 = fir.load %4 : !fir.ref>> %6 = fir.box_addr %5 : (!fir.box>) -> !fir.ptr %7 = fir.convert %6 : (!fir.ptr) -> !fir.ref fir.call @_QPtest2(%7) fastmath : (!fir.ref) -> () return } func.func private @_QPtest2(!fir.ref) // ----- // Two dummy arguments of composite type consisting of an allocatable // component cannot alias: // module m // type t // real, allocatable :: allocatable_component // end type t // contains // subroutine test(a, b) // type(t) :: a, b // allocate(a%allocatable_component) // call test2(b%allocatable_component) // end subroutine test // end module m // CHECK-LABEL: Testing : "_QMmPtest" // FIXME: MayAlias must be NoAlias // CHECK: func.region0#0 <-> func.region0#1: MayAlias func.func @_QMmPtest(%arg0: !fir.ref>}>> {fir.bindc_name = "a"}, %arg1: !fir.ref>}>> {fir.bindc_name = "b"}) attributes {test.ptr = "func"} { %0 = fir.field_index allocatable_component, !fir.type<_QMmTt{allocatable_component:!fir.box>}> %1 = fir.coordinate_of %arg0, %0 : (!fir.ref>}>>, !fir.field) -> !fir.ref>> %2 = fir.allocmem f32 {uniq_name = "_QMmEallocatable_component.alloc"} %3 = fir.embox %2 : (!fir.heap) -> !fir.box> fir.store %3 to %1 : !fir.ref>> %4 = fir.field_index allocatable_component, !fir.type<_QMmTt{allocatable_component:!fir.box>}> %5 = fir.coordinate_of %arg1, %4 : (!fir.ref>}>>, !fir.field) -> !fir.ref>> %6 = fir.load %5 : !fir.ref>> %7 = fir.box_addr %6 : (!fir.box>) -> !fir.heap %8 = fir.convert %7 : (!fir.heap) -> !fir.ref fir.call @_QPtest2(%8) fastmath : (!fir.ref) -> () return } func.func private @_QPtest2(!fir.ref)