Skip to content

Commit 170578d

Browse files
[mlir][SPIRV] Do not access erased op in SPIRV->LLVM lowering (#148373)
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`. --------- Co-authored-by: Markus Böck <markus.boeck02@gmail.com>
1 parent bce3cbc commit 170578d

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

mlir/lib/Conversion/SPIRVToLLVM/SPIRVToLLVM.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -779,13 +779,15 @@ class GlobalVariablePattern
779779
auto linkage = storageClass == spirv::StorageClass::Private
780780
? LLVM::Linkage::Private
781781
: LLVM::Linkage::External;
782+
StringAttr locationAttrName = op.getLocationAttrName();
783+
IntegerAttr locationAttr = op.getLocationAttr();
782784
auto newGlobalOp = rewriter.replaceOpWithNewOp<LLVM::GlobalOp>(
783785
op, dstType, isConstant, linkage, op.getSymName(), Attribute(),
784786
/*alignment=*/0, storageClassToAddressSpace(clientAPI, storageClass));
785787

786788
// Attach location attribute if applicable
787-
if (op.getLocationAttr())
788-
newGlobalOp->setAttr(op.getLocationAttrName(), op.getLocationAttr());
789+
if (locationAttr)
790+
newGlobalOp->setAttr(locationAttrName, locationAttr);
789791

790792
return success();
791793
}
@@ -1426,7 +1428,6 @@ class SelectionPattern : public SPIRVToLLVMConversion<spirv::SelectionOp> {
14261428
headerBlock->getOperations().front());
14271429
if (!condBrOp)
14281430
return failure();
1429-
rewriter.eraseBlock(headerBlock);
14301431

14311432
// Branch from merge block to continue block.
14321433
auto *mergeBlock = op.getMergeBlock();
@@ -1444,6 +1445,7 @@ class SelectionPattern : public SPIRVToLLVMConversion<spirv::SelectionOp> {
14441445
falseBlock,
14451446
condBrOp.getFalseTargetOperands());
14461447

1448+
rewriter.eraseBlock(headerBlock);
14471449
rewriter.inlineRegionBefore(op.getBody(), continueBlock);
14481450
rewriter.replaceOp(op, continueBlock->getArguments());
14491451
return success();

0 commit comments

Comments
 (0)