Fix memory leaks in mlir/unittests/MLIRTableGenTests
authorMehdi Amini <joker.eph@gmail.com>
Sat, 2 Oct 2021 21:05:22 +0000 (21:05 +0000)
committerMehdi Amini <joker.eph@gmail.com>
Sat, 2 Oct 2021 21:06:02 +0000 (21:06 +0000)
Trying to get MLIR ASAN-clean.

mlir/unittests/TableGen/OpBuildGen.cpp

index c5ef923..672e441 100644 (file)
@@ -73,21 +73,21 @@ protected:
   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 @@ protected:
   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 @@ protected:
 /// 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