[Mlir-commits] [mlir] [mlir] [bufferize] fix crash when bufferize function without func.return returning op (PR #120675)

Matthias Springer llvmlistbot at llvm.org
Tue Dec 24 00:22:40 PST 2024


================
@@ -434,11 +434,11 @@ static void foldMemRefCasts(func::FuncOp funcOp) {
     return;
 
   // Compute the common result types of all return ops.
-  SmallVector<func::ReturnOp> returnOps = getReturnOps(funcOp);
+  SmallVector<Operation *> returnOps = getReturnOps(funcOp);
   SmallVector<Type> resultTypes = getReturnTypes(returnOps);
 
   // Remove direct casts.
-  for (func::ReturnOp returnOp : returnOps) {
+  for (Operation *returnOp : returnOps) {
     for (OpOperand &operand : returnOp->getOpOperands()) {
----------------
matthias-springer wrote:

This looks a bit suspicious to me: Querying operands like this is not generally correct for `Operation *`. A return-like op could have additional operands that are not returned. The correct thing to do is probably to have a `ReturnOpInterface` (instead of a trait). This reminds me a bit of `BranchOpInterface`, which has interface methods to query forwarded/produced operands.

(Not saying that you should implement it, I'd like to understand the use case first.)


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


More information about the Mlir-commits mailing list