[flang-commits] [flang] [flang][hlfir] fix issue 118922 (PR #119219)

Tom Eccles via flang-commits flang-commits at lists.llvm.org
Mon Dec 9 07:14:18 PST 2024


================
@@ -806,8 +806,13 @@ struct ElementalOpConversion
     // elemental is a "view" over a variable (e.g parentheses or transpose).
     if (auto asExpr = elementValue.getDefiningOp<hlfir::AsExprOp>()) {
       if (asExpr->hasOneUse() && !asExpr.isMove()) {
-        elementValue = hlfir::Entity{asExpr.getVar()};
-        rewriter.eraseOp(asExpr);
+        // Check that the asExpr is the final operation before the yield,
+        // otherwise, clean-ups could impact the memory being re-used.
+        mlir::Operation *nextOp = asExpr->getNextNode();
+        if (nextOp && nextOp == yield.getOperation()) {
----------------
tblah wrote:

nit: `yield.getOperation()` cannot return `nullptr` and so there is no need to check if `nextOp` is non-null.

It is okay if you prefer to keep the redundant check for clarity.

https://github.com/llvm/llvm-project/pull/119219


More information about the flang-commits mailing list