xref: /llvm-project/flang/test/HLFIR/order_assignments/where-cleanup.f90 (revision c7c5666aac543a49b485a133f4a94865e2613a43)
1// Test hlfir.where masked region cleanup lowering (the freemem in the tests).
2// RUN: fir-opt %s --lower-hlfir-ordered-assignments | FileCheck %s
3
4func.func @loop_cleanup(%mask : !fir.ref<!fir.array<2x!fir.logical<4>>>, %x : !fir.ref<!fir.array<2xf32>>, %y : !fir.ref<!fir.array<2xf32>>) {
5    hlfir.where {
6        %1 = fir.allocmem !fir.array<10xi32>
7        hlfir.yield %mask : !fir.ref<!fir.array<2x!fir.logical<4>>> cleanup {
8          fir.freemem %1 : !fir.heap<!fir.array<10xi32>>
9        }
10    } do {
11      hlfir.region_assign {
12        %1 = fir.allocmem !fir.array<1xi32>
13        %2 = fir.allocmem !fir.array<2xi32>
14        hlfir.yield %x : !fir.ref<!fir.array<2xf32>> cleanup {
15          fir.freemem %2 : !fir.heap<!fir.array<2xi32>>
16          fir.freemem %1 : !fir.heap<!fir.array<1xi32>>
17        }
18      } to {
19        %1 = fir.allocmem !fir.array<3xi32>
20        %2 = fir.allocmem !fir.array<4xi32>
21        hlfir.yield %y : !fir.ref<!fir.array<2xf32>> cleanup {
22          fir.freemem %2 : !fir.heap<!fir.array<4xi32>>
23          fir.freemem %1 : !fir.heap<!fir.array<3xi32>>
24        }
25      }
26    }
27  return
28}
29// CHECK-LABEL:   func.func @loop_cleanup(
30// CHECK:           %[[VAL_3:.*]] = fir.allocmem !fir.array<10xi32>
31// CHECK:           fir.do_loop
32// CHECK:             fir.if
33// CHECK:               %[[VAL_11:.*]] = fir.allocmem !fir.array<1xi32>
34// CHECK:               %[[VAL_12:.*]] = fir.allocmem !fir.array<2xi32>
35// CHECK:               %[[VAL_14:.*]] = fir.allocmem !fir.array<3xi32>
36// CHECK:               %[[VAL_15:.*]] = fir.allocmem !fir.array<4xi32>
37// CHECK:               hlfir.assign
38// CHECK:               fir.freemem %[[VAL_15]] : !fir.heap<!fir.array<4xi32>>
39// CHECK:               fir.freemem %[[VAL_14]] : !fir.heap<!fir.array<3xi32>>
40// CHECK:               fir.freemem %[[VAL_12]] : !fir.heap<!fir.array<2xi32>>
41// CHECK:               fir.freemem %[[VAL_11]] : !fir.heap<!fir.array<1xi32>>
42// CHECK:             }
43// CHECK:           }
44// CHECK:           fir.freemem %[[VAL_3]] : !fir.heap<!fir.array<10xi32>>
45