[Mlir-commits] [mlir] 107198f - Fix memory leaks in mlir/unittests/MLIRTableGenTests

Mehdi Amini llvmlistbot at llvm.org
Sat Oct 2 14:06:10 PDT 2021


Author: Mehdi Amini
Date: 2021-10-02T21:06:02Z
New Revision: 107198fe7de8c0a03517760fcaa611cfc673b0b6

URL: https://github.com/llvm/llvm-project/commit/107198fe7de8c0a03517760fcaa611cfc673b0b6
DIFF: https://github.com/llvm/llvm-project/commit/107198fe7de8c0a03517760fcaa611cfc673b0b6.diff

LOG: Fix memory leaks in mlir/unittests/MLIRTableGenTests

Trying to get MLIR ASAN-clean.

Added: 
    

Modified: 
    mlir/unittests/TableGen/OpBuildGen.cpp

Removed: 
    


################################################################################
diff  --git a/mlir/unittests/TableGen/OpBuildGen.cpp b/mlir/unittests/TableGen/OpBuildGen.cpp
index c5ef9230536ee..672e44130dc61 100644
--- a/mlir/unittests/TableGen/OpBuildGen.cpp
+++ b/mlir/unittests/TableGen/OpBuildGen.cpp
@@ -73,21 +73,21 @@ class OpBuildGenTest : public ::testing::Test {
   template <typename OpTy>
   void testSingleVariadicInputInferredType() {
     // Test separate arg, separate param build method.
-    auto op = builder.create<OpTy>(loc, i32Ty, ValueRange{cstI32, cstI32});
-    verifyOp(std::move(op), {i32Ty}, {cstI32, cstI32}, noAttrs);
+    auto op = builder.create<OpTy>(loc, i32Ty, ValueRange{*cstI32, *cstI32});
+    verifyOp(std::move(op), {i32Ty}, {*cstI32, *cstI32}, noAttrs);
 
     // Test collective params build method.
     op =
-        builder.create<OpTy>(loc, TypeRange{i32Ty}, ValueRange{cstI32, cstI32});
-    verifyOp(std::move(op), {i32Ty}, {cstI32, cstI32}, noAttrs);
+        builder.create<OpTy>(loc, TypeRange{i32Ty}, ValueRange{*cstI32, *cstI32});
+    verifyOp(std::move(op), {i32Ty}, {*cstI32, *cstI32}, noAttrs);
 
     // Test build method with no result types, default value of attributes.
-    op = builder.create<OpTy>(loc, ValueRange{cstI32, cstI32});
-    verifyOp(std::move(op), {i32Ty}, {cstI32, cstI32}, noAttrs);
+    op = builder.create<OpTy>(loc, ValueRange{*cstI32, *cstI32});
+    verifyOp(std::move(op), {i32Ty}, {*cstI32, *cstI32}, noAttrs);
 
     // Test build method with no result types and supplied attributes.
-    op = builder.create<OpTy>(loc, ValueRange{cstI32, cstI32}, attrs);
-    verifyOp(std::move(op), {i32Ty}, {cstI32, cstI32}, attrs);
+    op = builder.create<OpTy>(loc, ValueRange{*cstI32, *cstI32}, attrs);
+    verifyOp(std::move(op), {i32Ty}, {*cstI32, *cstI32}, attrs);
   }
 
 protected:
@@ -96,8 +96,8 @@ class OpBuildGenTest : public ::testing::Test {
   Location loc;
   Type i32Ty;
   Type f32Ty;
-  test::TableGenConstant cstI32;
-  test::TableGenConstant cstF32;
+  OwningOpRef<test::TableGenConstant> cstI32;
+  OwningOpRef<test::TableGenConstant> cstF32;
 
   ArrayRef<NamedAttribute> noAttrs;
   std::vector<NamedAttribute> attrStorage;
@@ -107,22 +107,22 @@ class OpBuildGenTest : public ::testing::Test {
 /// Test basic build methods.
 TEST_F(OpBuildGenTest, BasicBuildMethods) {
   // Test separate args, separate results build method.
-  auto op = builder.create<test::TableGenBuildOp0>(loc, i32Ty, cstI32);
-  verifyOp(op, {i32Ty}, {cstI32}, noAttrs);
+  auto op = builder.create<test::TableGenBuildOp0>(loc, i32Ty, *cstI32);
+  verifyOp(op, {i32Ty}, {*cstI32}, noAttrs);
 
   // Test separate args, collective results build method.
-  op = builder.create<test::TableGenBuildOp0>(loc, TypeRange{i32Ty}, cstI32);
-  verifyOp(op, {i32Ty}, {cstI32}, noAttrs);
+  op = builder.create<test::TableGenBuildOp0>(loc, TypeRange{i32Ty}, *cstI32);
+  verifyOp(op, {i32Ty}, {*cstI32}, noAttrs);
 
   // Test collective args, collective params build method.
   op = builder.create<test::TableGenBuildOp0>(loc, TypeRange{i32Ty},
-                                              ValueRange{cstI32});
-  verifyOp(op, {i32Ty}, {cstI32}, noAttrs);
+                                              ValueRange{*cstI32});
+  verifyOp(op, {i32Ty}, {*cstI32}, noAttrs);
 
   // Test collective args, collective results, non-empty attributes
   op = builder.create<test::TableGenBuildOp0>(loc, TypeRange{i32Ty},
-                                              ValueRange{cstI32}, attrs);
-  verifyOp(op, {i32Ty}, {cstI32}, attrs);
+                                              ValueRange{*cstI32}, attrs);
+  verifyOp(op, {i32Ty}, {*cstI32}, attrs);
 }
 
 /// The following 3 tests exercise build methods generated for operations
@@ -139,25 +139,25 @@ TEST_F(OpBuildGenTest, BasicBuildMethods) {
 TEST_F(OpBuildGenTest, BuildMethodsSingleVariadicArgAndResult) {
   // Test collective args, collective results method, building a unary op.
   auto op = builder.create<test::TableGenBuildOp1>(loc, TypeRange{i32Ty},
-                                                   ValueRange{cstI32});
-  verifyOp(std::move(op), {i32Ty}, {cstI32}, noAttrs);
+                                                   ValueRange{*cstI32});
+  verifyOp(std::move(op), {i32Ty}, {*cstI32}, noAttrs);
 
   // Test collective args, collective results method, building a unary op with
   // named attributes.
   op = builder.create<test::TableGenBuildOp1>(loc, TypeRange{i32Ty},
-                                              ValueRange{cstI32}, attrs);
-  verifyOp(std::move(op), {i32Ty}, {cstI32}, attrs);
+                                              ValueRange{*cstI32}, attrs);
+  verifyOp(std::move(op), {i32Ty}, {*cstI32}, attrs);
 
   // Test collective args, collective results method, building a binary op.
   op = builder.create<test::TableGenBuildOp1>(loc, TypeRange{i32Ty, f32Ty},
-                                              ValueRange{cstI32, cstF32});
-  verifyOp(std::move(op), {i32Ty, f32Ty}, {cstI32, cstF32}, noAttrs);
+                                              ValueRange{*cstI32, *cstF32});
+  verifyOp(std::move(op), {i32Ty, f32Ty}, {*cstI32, *cstF32}, noAttrs);
 
   // Test collective args, collective results method, building a binary op with
   // named attributes.
   op = builder.create<test::TableGenBuildOp1>(
-      loc, TypeRange{i32Ty, f32Ty}, ValueRange{cstI32, cstF32}, attrs);
-  verifyOp(std::move(op), {i32Ty, f32Ty}, {cstI32, cstF32}, attrs);
+      loc, TypeRange{i32Ty, f32Ty}, ValueRange{*cstI32, *cstF32}, attrs);
+  verifyOp(std::move(op), {i32Ty, f32Ty}, {*cstI32, *cstF32}, attrs);
 }
 
 /// Test build methods for an Op with a single varadic arg and a non-variadic
@@ -165,23 +165,23 @@ TEST_F(OpBuildGenTest, BuildMethodsSingleVariadicArgAndResult) {
 TEST_F(OpBuildGenTest, BuildMethodsSingleVariadicArgNonVariadicResults) {
   // Test separate arg, separate param build method.
   auto op =
-      builder.create<test::TableGenBuildOp1>(loc, i32Ty, ValueRange{cstI32});
-  verifyOp(std::move(op), {i32Ty}, {cstI32}, noAttrs);
+      builder.create<test::TableGenBuildOp1>(loc, i32Ty, ValueRange{*cstI32});
+  verifyOp(std::move(op), {i32Ty}, {*cstI32}, noAttrs);
 
   // Test collective params build method, no attributes.
   op = builder.create<test::TableGenBuildOp1>(loc, TypeRange{i32Ty},
-                                              ValueRange{cstI32});
-  verifyOp(std::move(op), {i32Ty}, {cstI32}, noAttrs);
+                                              ValueRange{*cstI32});
+  verifyOp(std::move(op), {i32Ty}, {*cstI32}, noAttrs);
 
   // Test collective params build method no attributes, 2 inputs.
   op = builder.create<test::TableGenBuildOp1>(loc, TypeRange{i32Ty},
-                                              ValueRange{cstI32, cstF32});
-  verifyOp(std::move(op), {i32Ty}, {cstI32, cstF32}, noAttrs);
+                                              ValueRange{*cstI32, *cstF32});
+  verifyOp(std::move(op), {i32Ty}, {*cstI32, *cstF32}, noAttrs);
 
   // Test collective params build method, non-empty attributes.
   op = builder.create<test::TableGenBuildOp1>(
-      loc, TypeRange{i32Ty}, ValueRange{cstI32, cstF32}, attrs);
-  verifyOp(std::move(op), {i32Ty}, {cstI32, cstF32}, attrs);
+      loc, TypeRange{i32Ty}, ValueRange{*cstI32, *cstF32}, attrs);
+  verifyOp(std::move(op), {i32Ty}, {*cstI32, *cstF32}, attrs);
 }
 
 /// Test build methods for an Op with a single varadic arg and multiple variadic
@@ -190,18 +190,18 @@ TEST_F(OpBuildGenTest,
        BuildMethodsSingleVariadicArgAndMultipleVariadicResults) {
   // Test separate arg, separate param build method.
   auto op = builder.create<test::TableGenBuildOp3>(
-      loc, TypeRange{i32Ty}, TypeRange{f32Ty}, ValueRange{cstI32});
-  verifyOp(std::move(op), {i32Ty, f32Ty}, {cstI32}, noAttrs);
+      loc, TypeRange{i32Ty}, TypeRange{f32Ty}, ValueRange{*cstI32});
+  verifyOp(std::move(op), {i32Ty, f32Ty}, {*cstI32}, noAttrs);
 
   // Test collective params build method, no attributes.
   op = builder.create<test::TableGenBuildOp3>(loc, TypeRange{i32Ty, f32Ty},
-                                              ValueRange{cstI32});
-  verifyOp(std::move(op), {i32Ty, f32Ty}, {cstI32}, noAttrs);
+                                              ValueRange{*cstI32});
+  verifyOp(std::move(op), {i32Ty, f32Ty}, {*cstI32}, noAttrs);
 
   // Test collective params build method, with attributes.
   op = builder.create<test::TableGenBuildOp3>(loc, TypeRange{i32Ty, f32Ty},
-                                              ValueRange{cstI32}, attrs);
-  verifyOp(std::move(op), {i32Ty, f32Ty}, {cstI32}, attrs);
+                                              ValueRange{*cstI32}, attrs);
+  verifyOp(std::move(op), {i32Ty, f32Ty}, {*cstI32}, attrs);
 }
 
 // The next 2 tests test supression of ambiguous build methods for ops that


        


More information about the Mlir-commits mailing list