diff --git a/flang/lib/Optimizer/HLFIR/Transforms/BufferizeHLFIR.cpp b/flang/lib/Optimizer/HLFIR/Transforms/BufferizeHLFIR.cpp --- a/flang/lib/Optimizer/HLFIR/Transforms/BufferizeHLFIR.cpp +++ b/flang/lib/Optimizer/HLFIR/Transforms/BufferizeHLFIR.cpp @@ -351,10 +351,12 @@ mlir::Operation *endAssociate) { for (mlir::Operation *useOp : value.getUsers()) if (!mlir::isa(useOp) && useOp != currentUse) { - // hlfir.shape_of will not disrupt cleanup so it is safe for - // hlfir.associate. hlfir.shape_of might read the box dimensions and so it - // needs to come before the hflir.end_associate (which may deallocate). - if (mlir::isa(useOp)) { + // hlfir.shape_of and hlfir.get_length will not disrupt cleanup so it is + // safe for hlfir.associate. These operations might read from the box and + // so they need to come before the hflir.end_associate (which may + // deallocate). + if (mlir::isa(useOp) || + mlir::isa(useOp)) { if (!endAssociate) continue; // not known to occur in practice: