[flang-commits] [flang] [flang] fix a dangling else in allOtherUsesAreSafeForAssociate (PR #189748)

via flang-commits flang-commits at lists.llvm.org
Tue Mar 31 13:53:26 PDT 2026


https://github.com/yebinchon created https://github.com/llvm/llvm-project/pull/189748

Fix a dangling if condition in allOtherUsesAreSafeForAssociate that caused isBeforeInBlock to be called even when instructions were known to not be in the same block, triggering an assertion. The condition was changed to else if and added brackets.

>From 752e82056992a8e0a4ed994c118fdb6bb015cbb4 Mon Sep 17 00:00:00 2001
From: Yebin Chon <ychon at nvidia.com>
Date: Tue, 31 Mar 2026 13:50:26 -0700
Subject: [PATCH] fix a dangling else that caused isBeforeInBlock to be called
 when instructions were in different blocks

---
 flang/lib/Optimizer/HLFIR/Transforms/BufferizeHLFIR.cpp | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/flang/lib/Optimizer/HLFIR/Transforms/BufferizeHLFIR.cpp b/flang/lib/Optimizer/HLFIR/Transforms/BufferizeHLFIR.cpp
index 53ff13f5a9d28..35cbdd59cf5d8 100644
--- a/flang/lib/Optimizer/HLFIR/Transforms/BufferizeHLFIR.cpp
+++ b/flang/lib/Optimizer/HLFIR/Transforms/BufferizeHLFIR.cpp
@@ -382,11 +382,12 @@ static bool allOtherUsesAreSafeForAssociate(mlir::Value value,
         if (!endAssociate)
           continue;
         // If useOp dominates the endAssociate, then it is definitely safe.
-        if (useOp->getBlock() != endAssociate->getBlock())
+        if (useOp->getBlock() != endAssociate->getBlock()) {
           if (mlir::DominanceInfo{}.dominates(useOp, endAssociate))
             continue;
-        if (useOp->isBeforeInBlock(endAssociate))
+        } else if (useOp->isBeforeInBlock(endAssociate)) {
           continue;
+        }
       }
       return false;
     }



More information about the flang-commits mailing list