1 // check that hlfir.designate can be followed by alias analysis
3 // use --mlir-disable-threading so that the AA queries are serialised
4 // as well as its diagnostic output.
5 // RUN: fir-opt %s --test-fir-alias-analysis -split-input-file --mlir-disable-threading 2>&1 | FileCheck %s
7 // designate for a derived type component:
14 // subroutine test(arg)
17 // end subroutine test
20 // A global can't alias with a dummy argument
21 // CHECK: arg#0 <-> glbl%array#0: NoAlias
23 module attributes {fir.defaultkind = "a1c4d8i4l4r4", fir.kindmap = "", llvm.target_triple = "aarch64-unknown-linux-gnu"} {
24 fir.global @_QMmEglbl : !fir.type<_QMmTt{array:!fir.array<42xf32>}> {
25 %0 = fir.undefined !fir.type<_QMmTt{array:!fir.array<42xf32>}>
26 fir.has_value %0 : !fir.type<_QMmTt{array:!fir.array<42xf32>}>
28 func.func @_QMmPtest(%arg0: !fir.ref<!fir.array<42xf32>> {fir.bindc_name = "arg"}) {
29 %c42 = arith.constant 42 : index
30 %0 = fir.address_of(@_QMmEglbl) : !fir.ref<!fir.type<_QMmTt{array:!fir.array<42xf32>}>>
31 %1:2 = hlfir.declare %0 {uniq_name = "_QMmEglbl"} : (!fir.ref<!fir.type<_QMmTt{array:!fir.array<42xf32>}>>) -> (!fir.ref<!fir.type<_QMmTt{array:!fir.array<42xf32>}>>, !fir.ref<!fir.type<_QMmTt{array:!fir.array<42xf32>}>>)
32 %2 = fir.shape %c42 : (index) -> !fir.shape<1>
33 %3:2 = hlfir.declare %arg0(%2) {uniq_name = "_QMmFtestEarg", test.ptr = "arg"} : (!fir.ref<!fir.array<42xf32>>, !fir.shape<1>) -> (!fir.ref<!fir.array<42xf32>>, !fir.ref<!fir.array<42xf32>>)
34 %4 = hlfir.designate %1#0{"array"} shape %2 {test.ptr = "glbl%array"} : (!fir.ref<!fir.type<_QMmTt{array:!fir.array<42xf32>}>>, !fir.shape<1>) -> !fir.ref<!fir.array<42xf32>>
35 hlfir.assign %3#0 to %4 : !fir.ref<!fir.array<42xf32>>, !fir.ref<!fir.array<42xf32>>
42 // designate for an array element
44 // two dummy arguments don't alias
45 // CHECK: array0#0 <-> array1#0: NoAlias
47 func.func @array_element(%arg0: !fir.ref<!fir.array<2x42xi32>>, %arg1: !fir.ref<!fir.array<2x42xi32>>) {
48 %c0 = arith.constant 0 : index
49 %c1 = arith.constant 1 : index
50 %c41 = arith.constant 41 : index
51 %c42 = arith.constant 42 : index
52 %shape = fir.shape %c42 : (index) -> !fir.shape<1>
53 %array0 = hlfir.designate %arg0 (%c0, %c0:%c41:%c1) shape %shape {test.ptr = "array0"} : (!fir.ref<!fir.array<2x42xi32>>, index, index, index, index, !fir.shape<1>) -> !fir.box<!fir.array<?xi32>>
54 %array1 = hlfir.designate %arg1 (%c1, %c0:%c41:%c1) shape %shape {test.ptr = "array1"} : (!fir.ref<!fir.array<2x42xi32>>, index, index, index, index, !fir.shape<1>) -> !fir.box<!fir.array<?xi32>>
60 // FIXME: designate doesn't understand non-overlappning array indices
61 // make sure that we say MayAlias and not MustAlias until array indexes are understood
62 // CHECK: array2#0 <-> array3#0: MayAlias
64 func.func @array_element_same_source(%arg0: !fir.ref<!fir.array<2x42xi32>>) {
65 %c0 = arith.constant 0 : index
66 %c1 = arith.constant 1 : index
67 %c41 = arith.constant 41 : index
68 %c42 = arith.constant 42 : index
69 %shape = fir.shape %c42 : (index) -> !fir.shape<1>
70 %array2 = hlfir.designate %arg0 (%c0, %c0:%c41:%c1) shape %shape {test.ptr = "array2"} : (!fir.ref<!fir.array<2x42xi32>>, index, index, index, index, !fir.shape<1>) -> !fir.box<!fir.array<?xi32>>
71 %array3 = hlfir.designate %arg0 (%c1, %c0:%c41:%c1) shape %shape {test.ptr = "array3"} : (!fir.ref<!fir.array<2x42xi32>>, index, index, index, index, !fir.shape<1>) -> !fir.box<!fir.array<?xi32>>