blob: 2840c3c68d701ac42934b9de5dff67422c644b23 [file] [log] [blame]
Jean Perier3ed899c2022-03-17 09:55:561// Test overlapping assignment of derived type arrays with allocatable components.
2// This requires initializing the allocatable components to an unallocated status
3// before they can be used in component assignments, and to deallocate the components
4// that may have been allocated in the end.
5
6// RUN: fir-opt --array-value-copy %s | FileCheck %s
Slava Zakharin59b18b52023-01-21 03:58:367// RUN: fir-opt --array-value-copy="optimize-conflicts=true" %s | FileCheck %s
Jean Perier3ed899c2022-03-17 09:55:568
9
River Riddlea6cef032022-05-12 20:36:0510!t_with_alloc_comp = !fir.type<t{i:!fir.box<!fir.heap<!fir.array<?xi32>>>}>
River Riddlea83080202022-04-21 04:39:2211func.func private @custom_assign(!fir.ref<!t_with_alloc_comp>, !fir.ref<!t_with_alloc_comp>)
12func.func @test_overlap_with_alloc_components(%arg0: !fir.ref<!fir.array<10x!t_with_alloc_comp>>) {
Jean Perier3ed899c2022-03-17 09:55:5613 %0 = fir.alloca !fir.box<!t_with_alloc_comp>
14 %c10 = arith.constant 10 : index
15 %c9 = arith.constant 9 : index
16 %c1 = arith.constant 1 : index
17 %c-1 = arith.constant -1 : index
18 %c0 = arith.constant 0 : index
19 %1 = fir.shape %c10 : (index) -> !fir.shape<1>
20 %6 = fir.slice %c10, %c1, %c-1 : (index, index, index) -> !fir.slice<1>
21 %2 = fir.array_load %arg0(%1) : (!fir.ref<!fir.array<10x!t_with_alloc_comp>>, !fir.shape<1>) -> !fir.array<10x!t_with_alloc_comp>
22 %7 = fir.array_load %arg0(%1) [%6] : (!fir.ref<!fir.array<10x!t_with_alloc_comp>>, !fir.shape<1>, !fir.slice<1>) -> !fir.array<10x!t_with_alloc_comp>
23 %9 = fir.do_loop %arg1 = %c0 to %c9 step %c1 unordered iter_args(%arg2 = %2) -> (!fir.array<10x!t_with_alloc_comp>) {
24 %10 = fir.array_access %7, %arg1 : (!fir.array<10x!t_with_alloc_comp>, index) -> !fir.ref<!t_with_alloc_comp>
25 %11 = fir.array_access %arg2, %arg1 : (!fir.array<10x!t_with_alloc_comp>, index) -> !fir.ref<!t_with_alloc_comp>
26 fir.call @custom_assign(%11, %10) : (!fir.ref<!t_with_alloc_comp>, !fir.ref<!t_with_alloc_comp>) -> none
27 %19 = fir.array_amend %arg2, %11 : (!fir.array<10x!t_with_alloc_comp>, !fir.ref<!t_with_alloc_comp>) -> !fir.array<10x!t_with_alloc_comp>
28 fir.result %19 : !fir.array<10x!t_with_alloc_comp>
29 }
30 fir.array_merge_store %2, %9 to %arg0 : !fir.array<10x!t_with_alloc_comp>, !fir.array<10x!t_with_alloc_comp>, !fir.ref<!fir.array<10x!t_with_alloc_comp>>
31 return
32}
33
34// CHECK-LABEL: func @test_overlap_with_alloc_components(
35// CHECK-SAME: %[[VAL_0:.*]]: !fir.ref<!fir.array<10x!fir.type<t{i:!fir.box<!fir.heap<!fir.array<?xi32>>>}>>>) {
36// CHECK: %[[VAL_4:.*]] = arith.constant 10 : index
37// CHECK: %[[VAL_6:.*]] = arith.constant 1 : index
38// CHECK: %[[VAL_7:.*]] = arith.constant -1 : index
39// CHECK: %[[VAL_9:.*]] = fir.shape %[[VAL_4]] : (index) -> !fir.shape<1>
40// CHECK: %[[VAL_10:.*]] = fir.slice %[[VAL_4]], %[[VAL_6]], %[[VAL_7]] : (index, index, index) -> !fir.slice<1>
41// CHECK: %[[VAL_11:.*]] = fir.allocmem !fir.array<10x!fir.type<t{i:!fir.box<!fir.heap<!fir.array<?xi32>>>}>>
Valentin Clement11760b32022-12-06 14:02:1442// CHECK: %[[VAL_12:.*]] = fir.embox %[[VAL_11]](%[[VAL_9]]) : (!fir.heap<!fir.array<10x!fir.type<t{i:!fir.box<!fir.heap<!fir.array<?xi32>>>}>>>, !fir.shape<1>) -> !fir.box<!fir.heap<!fir.array<10x!fir.type<t{i:!fir.box<!fir.heap<!fir.array<?xi32>>>}>>>>
43// CHECK: %[[VAL_16:.*]] = fir.convert %[[VAL_12]] : (!fir.box<!fir.heap<!fir.array<10x!fir.type<t{i:!fir.box<!fir.heap<!fir.array<?xi32>>>}>>>>) -> !fir.box<none>
Jean Perier3ed899c2022-03-17 09:55:5644// CHECK: fir.call @_FortranAInitialize(%[[VAL_16]], %{{.*}}, %{{.*}}) : (!fir.box<none>, !fir.ref<i8>, i32) -> none
45// CHECK: fir.do_loop {{.*}} {
46// CHECK: fir.call @_FortranAAssign
47// CHECK: }
48// CHECK: fir.do_loop {{.*}} {
49// CHECK: fir.call @custom_assign
50// CHECK: }
51// CHECK: fir.do_loop %{{.*}} {
52// CHECK: fir.call @_FortranAAssign
53// CHECK: }
Valentin Clement11760b32022-12-06 14:02:1454// CHECK: %[[VAL_72:.*]] = fir.convert %[[VAL_12]] : (!fir.box<!fir.heap<!fir.array<10x!fir.type<t{i:!fir.box<!fir.heap<!fir.array<?xi32>>>}>>>>) -> !fir.box<none>
Jean Perier3ed899c2022-03-17 09:55:5655// CHECK: %[[VAL_73:.*]] = fir.call @_FortranADestroy(%[[VAL_72]]) : (!fir.box<none>) -> none
56// CHECK: fir.freemem %[[VAL_11]]