// RUN: fir-opt --opt-bufferization %s | FileCheck %s // Verify that ElementalAssignBufferization does NOT fuse an elemental into the // assignment when a deallocation between the elemental and the assignment frees // memory that the elemental reads. Moving the elemental evaluation down to the // assignment would read freed memory. func.func @dealloc_conflict(%dst: !fir.box>, %n: index) { %c1 = arith.constant 1 : index %cst = arith.constant 1.000000e+00 : f32 %shape = fir.shape %n : (index) -> !fir.shape<1> %heap = fir.allocmem !fir.array, %n {uniq_name = ".src"} %src = fir.embox %heap(%shape) : (!fir.heap>, !fir.shape<1>) -> !fir.box> %elem = hlfir.elemental %shape unordered : (!fir.shape<1>) -> !hlfir.expr { ^bb0(%i: index): %d = hlfir.designate %src (%i) : (!fir.box>, index) -> !fir.ref %v = fir.load %d : !fir.ref %s = arith.addf %v, %cst fastmath : f32 hlfir.yield_element %s : f32 } // Deallocation of the elemental's read source between elemental and assign. fir.freemem %heap : !fir.heap> hlfir.assign %elem to %dst : !hlfir.expr, !fir.box> hlfir.destroy %elem : !hlfir.expr return } // CHECK-LABEL: func.func @dealloc_conflict // The elemental and the array-level assign must be preserved (no fusion). // CHECK: hlfir.elemental // CHECK: fir.freemem // CHECK: hlfir.assign %{{.*}} to %{{.*}} : !hlfir.expr, !fir.box>