Skip to content

Commit fadc38e

Browse files
[mlir][memref] Fix memory leaks in runtime verification tests (#85362)
Change `memref.alloc` to `memref.alloca`, which does not require manual deallocation.
1 parent 7c460c6 commit fadc38e

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed

mlir/test/Integration/Dialect/Memref/reinterpret-cast-runtime-verification.mlir

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ func.func @main() {
3434
%5 = arith.constant 5 : index
3535

3636
%alloca_1 = memref.alloca() : memref<1xf32>
37-
%alloc_4 = memref.alloc(%4) : memref<?xf32>
37+
%alloca_4 = memref.alloca() : memref<4xf32>
38+
%alloca_4_dyn = memref.cast %alloca_4 : memref<4xf32> to memref<?xf32>
3839

3940
// Offset is out-of-bounds
4041
// CHECK: ERROR: Runtime op verification failed
@@ -55,20 +56,20 @@ func.func @main() {
5556
// CHECK-NEXT: "memref.reinterpret_cast"(%{{.*}})
5657
// CHECK-NEXT: ^ result of reinterpret_cast is out-of-bounds of the base memref
5758
// CHECK-NEXT: Location: loc({{.*}})
58-
func.call @reinterpret_cast_fully_dynamic(%alloc_4, %0, %5, %1) : (memref<?xf32>, index, index, index) -> ()
59+
func.call @reinterpret_cast_fully_dynamic(%alloca_4_dyn, %0, %5, %1) : (memref<?xf32>, index, index, index) -> ()
5960

6061
// Stride is out-of-bounds
6162
// CHECK: ERROR: Runtime op verification failed
6263
// CHECK-NEXT: "memref.reinterpret_cast"(%{{.*}})
6364
// CHECK-NEXT: ^ result of reinterpret_cast is out-of-bounds of the base memref
6465
// CHECK-NEXT: Location: loc({{.*}})
65-
func.call @reinterpret_cast_fully_dynamic(%alloc_4, %0, %4, %4) : (memref<?xf32>, index, index, index) -> ()
66+
func.call @reinterpret_cast_fully_dynamic(%alloca_4_dyn, %0, %4, %4) : (memref<?xf32>, index, index, index) -> ()
6667

6768
// CHECK-NOT: ERROR: Runtime op verification failed
6869
func.call @reinterpret_cast(%alloca_1, %0) : (memref<1xf32>, index) -> ()
6970

7071
// CHECK-NOT: ERROR: Runtime op verification failed
71-
func.call @reinterpret_cast_fully_dynamic(%alloc_4, %0, %4, %1) : (memref<?xf32>, index, index, index) -> ()
72+
func.call @reinterpret_cast_fully_dynamic(%alloca_4_dyn, %0, %4, %1) : (memref<?xf32>, index, index, index) -> ()
7273

7374
return
7475
}

mlir/test/Integration/Dialect/Memref/subview-runtime-verification.mlir

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,15 @@ func.func @main() {
3838
%5 = arith.constant 5 : index
3939

4040
%alloca = memref.alloca() : memref<1xf32>
41-
%alloc = memref.alloc(%4) : memref<?x4xf32>
41+
%alloca_4 = memref.alloca() : memref<4x4xf32>
42+
%alloca_4_dyn = memref.cast %alloca_4 : memref<4x4xf32> to memref<?x4xf32>
4243

4344
// Offset is out-of-bounds
4445
// CHECK: ERROR: Runtime op verification failed
4546
// CHECK-NEXT: "memref.subview"
4647
// CHECK-NEXT: ^ subview is out-of-bounds of the base memref
4748
// CHECK-NEXT: Location: loc({{.*}})
48-
func.call @subview_dynamic_rank_reduce(%alloc, %5, %5, %1) : (memref<?x4xf32>, index, index, index) -> ()
49+
func.call @subview_dynamic_rank_reduce(%alloca_4_dyn, %5, %5, %1) : (memref<?x4xf32>, index, index, index) -> ()
4950

5051
// Offset is out-of-bounds
5152
// CHECK: ERROR: Runtime op verification failed
@@ -66,23 +67,23 @@ func.func @main() {
6667
// CHECK-NEXT: "memref.subview"
6768
// CHECK-NEXT: ^ subview is out-of-bounds of the base memref
6869
// CHECK-NEXT: Location: loc({{.*}})
69-
func.call @subview_dynamic(%alloc, %0, %5, %1) : (memref<?x4xf32>, index, index, index) -> ()
70+
func.call @subview_dynamic(%alloca_4_dyn, %0, %5, %1) : (memref<?x4xf32>, index, index, index) -> ()
7071

7172
// Stride is out-of-bounds
7273
// CHECK: ERROR: Runtime op verification failed
7374
// CHECK-NEXT: "memref.subview"
7475
// CHECK-NEXT: ^ subview is out-of-bounds of the base memref
7576
// CHECK-NEXT: Location: loc({{.*}})
76-
func.call @subview_dynamic(%alloc, %0, %4, %4) : (memref<?x4xf32>, index, index, index) -> ()
77+
func.call @subview_dynamic(%alloca_4_dyn, %0, %4, %4) : (memref<?x4xf32>, index, index, index) -> ()
7778

7879
// CHECK-NOT: ERROR: Runtime op verification failed
7980
func.call @subview(%alloca, %0) : (memref<1xf32>, index) -> ()
8081

8182
// CHECK-NOT: ERROR: Runtime op verification failed
82-
func.call @subview_dynamic(%alloc, %0, %4, %1) : (memref<?x4xf32>, index, index, index) -> ()
83+
func.call @subview_dynamic(%alloca_4_dyn, %0, %4, %1) : (memref<?x4xf32>, index, index, index) -> ()
8384

8485
// CHECK-NOT: ERROR: Runtime op verification failed
85-
func.call @subview_dynamic_rank_reduce(%alloc, %0, %1, %0) : (memref<?x4xf32>, index, index, index) -> ()
86+
func.call @subview_dynamic_rank_reduce(%alloca_4_dyn, %0, %1, %0) : (memref<?x4xf32>, index, index, index) -> ()
8687

8788

8889
return

0 commit comments

Comments
 (0)