[Mlir-commits] [mlir] [mlir][SPIRV] Do not access erased op in SPIRV->LLVM lowering (PR #148373)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Sat Jul 12 06:58:54 PDT 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-mlir
Author: Matthias Springer (matthias-springer)
<details>
<summary>Changes</summary>
This commit fixes two occurrences where an erased op was accessed at a later point of time. That won't work anymore in a One-Shot Dialect Conversion and triggers a use-after-free sanitizer error.
After the One-Shot Dialect Conversion refactoring, a `ConversionPatternRewriter` will behave more like a normal `PatternRewriter`.
---
Full diff: https://github.com/llvm/llvm-project/pull/148373.diff
1 Files Affected:
- (modified) mlir/lib/Conversion/SPIRVToLLVM/SPIRVToLLVM.cpp (+5-3)
``````````diff
diff --git a/mlir/lib/Conversion/SPIRVToLLVM/SPIRVToLLVM.cpp b/mlir/lib/Conversion/SPIRVToLLVM/SPIRVToLLVM.cpp
index cea9d1fdec809..e3aabb7e7e625 100644
--- a/mlir/lib/Conversion/SPIRVToLLVM/SPIRVToLLVM.cpp
+++ b/mlir/lib/Conversion/SPIRVToLLVM/SPIRVToLLVM.cpp
@@ -779,13 +779,15 @@ class GlobalVariablePattern
auto linkage = storageClass == spirv::StorageClass::Private
? LLVM::Linkage::Private
: LLVM::Linkage::External;
+ auto locationAttrName = op.getLocationAttrName();
+ auto locationAttr = op.getLocationAttr();
auto newGlobalOp = rewriter.replaceOpWithNewOp<LLVM::GlobalOp>(
op, dstType, isConstant, linkage, op.getSymName(), Attribute(),
/*alignment=*/0, storageClassToAddressSpace(clientAPI, storageClass));
// Attach location attribute if applicable
- if (op.getLocationAttr())
- newGlobalOp->setAttr(op.getLocationAttrName(), op.getLocationAttr());
+ if (locationAttr)
+ newGlobalOp->setAttr(locationAttrName, locationAttr);
return success();
}
@@ -1426,7 +1428,6 @@ class SelectionPattern : public SPIRVToLLVMConversion<spirv::SelectionOp> {
headerBlock->getOperations().front());
if (!condBrOp)
return failure();
- rewriter.eraseBlock(headerBlock);
// Branch from merge block to continue block.
auto *mergeBlock = op.getMergeBlock();
@@ -1444,6 +1445,7 @@ class SelectionPattern : public SPIRVToLLVMConversion<spirv::SelectionOp> {
falseBlock,
condBrOp.getFalseTargetOperands());
+ rewriter.eraseBlock(headerBlock);
rewriter.inlineRegionBefore(op.getBody(), continueBlock);
rewriter.replaceOp(op, continueBlock->getArguments());
return success();
``````````
</details>
https://github.com/llvm/llvm-project/pull/148373
More information about the Mlir-commits
mailing list