Skip to content

Commit 0ad6ac8

Browse files
authored
[NFC][MLIR] Fix: alloca promotion for AllocationOpInterface (#97672)
The std::optional returned by buildPromotedAlloc was directly dereferenced and assumed to be non-null, even though the documentation for AllocationOpInterface indicates that std::nullopt is a legal value if buffer stack promotion is not supported (and is the default value supplied by the TableGen interface file). This patch removes the direct dereference so that the optional can be null-checked prior to use. Co-authored-by: Nikhil Kalra <[email protected]>
1 parent 948862b commit 0ad6ac8

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

mlir/lib/Dialect/Bufferization/Transforms/BufferOptimizations.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -397,12 +397,12 @@ class BufferPlacementPromotion : BufferPlacementTransformationBase {
397397
OpBuilder builder(startOperation);
398398
Operation *allocOp = alloc.getDefiningOp();
399399
if (auto allocInterface = dyn_cast<AllocationOpInterface>(allocOp)) {
400-
Operation *alloca =
401-
allocInterface.buildPromotedAlloc(builder, alloc).value();
400+
std::optional<Operation *> alloca =
401+
allocInterface.buildPromotedAlloc(builder, alloc);
402402
if (!alloca)
403403
continue;
404404
// Replace the original alloc by a newly created alloca.
405-
allocOp->replaceAllUsesWith(alloca);
405+
allocOp->replaceAllUsesWith(alloca.value());
406406
allocOp->erase();
407407
}
408408
}

0 commit comments

Comments
 (0)