Skip to content

Commit

Permalink
[mlir][bufferization] Fix handling of indirect function calls (llvm#9…
Browse files Browse the repository at this point in the history
…4896)

This commit fixes a crash in the ownership-based buffer deallocation
pass when indirectly calling a function via SSA value. Such functions
must be conservatively assumed to be public.

Fixes llvm#94780.
  • Loading branch information
matthias-springer committed Jun 10, 2024
1 parent 9d0754a commit 13896b6
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -822,10 +822,11 @@ FailureOr<Operation *> BufferDeallocation::handleInterface(CallOpInterface op) {

// Lookup the function operation and check if it has private visibility. If
// the function is referenced by SSA value instead of a Symbol, it's assumed
// to be always private.
// to be public. (And we cannot easily change the type of the SSA value
// anyway.)
Operation *funcOp = op.resolveCallable(state.getSymbolTable());
bool isPrivate = true;
if (auto symbol = dyn_cast<SymbolOpInterface>(funcOp))
bool isPrivate = false;
if (auto symbol = dyn_cast_or_null<SymbolOpInterface>(funcOp))
isPrivate = symbol.isPrivate() && !symbol.isDeclaration();

// If the private-function-dynamic-ownership option is enabled and we are
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,3 +131,22 @@ func.func @g(%arg0: memref<f32>) -> memref<f32> {
// CHECK-DYNAMIC-LABEL: func private @f
// CHECK-DYNAMIC-SAME: (memref<f32>) -> memref<f32>
// CHECK-DYNAMIC: call @f({{.*}}) : (memref<f32>) -> memref<f32>

// -----

func.func @func_call_indirect(%m: memref<?xf32>, %f: (memref<?xf32>) -> (memref<?xf32>)) {
%0 = func.call_indirect %f(%m) : (memref<?xf32>) -> (memref<?xf32>)
return
}

// CHECK-LABEL: func @func_call_indirect(
// CHECK: %[[true:.*]] = arith.constant true
// CHECK: %[[call:.*]] = call_indirect {{.*}} : (memref<?xf32>) -> memref<?xf32>
// CHECK: %[[base_call:.*]], %{{.*}}, %{{.*}}, %{{.*}} = memref.extract_strided_metadata %[[call]]
// CHECK: bufferization.dealloc (%[[base_call]] : {{.*}}) if (%[[true]])

// CHECK-DYNAMIC-LABEL: func @func_call_indirect(
// CHECK-DYNAMIC: %[[true:.*]] = arith.constant true
// CHECK-DYNAMIC: %[[call:.*]] = call_indirect {{.*}} : (memref<?xf32>) -> memref<?xf32>
// CHECK-DYNAMIC: %[[base_call:.*]], %{{.*}}, %{{.*}}, %{{.*}} = memref.extract_strided_metadata %[[call]]
// CHECK-DYNAMIC: bufferization.dealloc (%[[base_call]] : {{.*}}) if (%[[true]])

0 comments on commit 13896b6

Please sign in to comment.