aboutsummaryrefslogtreecommitdiff
path: root/mlir/unittests/IR
diff options
context:
space:
mode:
Diffstat (limited to 'mlir/unittests/IR')
-rw-r--r--mlir/unittests/IR/AttributeTest.cpp31
-rw-r--r--mlir/unittests/IR/SymbolTableTest.cpp34
2 files changed, 60 insertions, 5 deletions
diff --git a/mlir/unittests/IR/AttributeTest.cpp b/mlir/unittests/IR/AttributeTest.cpp
index a55592d..fd40404 100644
--- a/mlir/unittests/IR/AttributeTest.cpp
+++ b/mlir/unittests/IR/AttributeTest.cpp
@@ -477,8 +477,9 @@ TEST(SubElementTest, Nested) {
{strAttr, trueAttr, falseAttr, boolArrayAttr, dictAttr}));
}
-// Test how many times we call copy-ctor when building an attribute.
-TEST(CopyCountAttr, CopyCount) {
+// Test how many times we call copy-ctor when building an attribute with the
+// 'get' method.
+TEST(CopyCountAttr, CopyCountGet) {
MLIRContext context;
context.loadDialect<test::TestDialect>();
@@ -489,15 +490,35 @@ TEST(CopyCountAttr, CopyCount) {
test::CopyCount::counter = 0;
test::TestCopyCountAttr::get(&context, std::move(copyCount));
#ifndef NDEBUG
- // One verification enabled only in assert-mode requires a copy.
- EXPECT_EQ(counter1, 1);
- EXPECT_EQ(test::CopyCount::counter, 1);
+ // One verification enabled only in assert-mode requires two copies: one for
+ // calling 'verifyInvariants' and one for calling 'verify' inside
+ // 'verifyInvariants'.
+ EXPECT_EQ(counter1, 2);
+ EXPECT_EQ(test::CopyCount::counter, 2);
#else
EXPECT_EQ(counter1, 0);
EXPECT_EQ(test::CopyCount::counter, 0);
#endif
}
+// Test how many times we call copy-ctor when building an attribute with the
+// 'getChecked' method.
+TEST(CopyCountAttr, CopyCountGetChecked) {
+ MLIRContext context;
+ context.loadDialect<test::TestDialect>();
+ test::CopyCount::counter = 0;
+ test::CopyCount copyCount("hello");
+ auto loc = UnknownLoc::get(&context);
+ test::TestCopyCountAttr::getChecked(loc, &context, std::move(copyCount));
+ int counter1 = test::CopyCount::counter;
+ test::CopyCount::counter = 0;
+ test::TestCopyCountAttr::getChecked(loc, &context, std::move(copyCount));
+ // The verifiers require two copies: one for calling 'verifyInvariants' and
+ // one for calling 'verify' inside 'verifyInvariants'.
+ EXPECT_EQ(counter1, 2);
+ EXPECT_EQ(test::CopyCount::counter, 2);
+}
+
// Test stripped printing using test dialect attribute.
TEST(CopyCountAttr, PrintStripped) {
MLIRContext context;
diff --git a/mlir/unittests/IR/SymbolTableTest.cpp b/mlir/unittests/IR/SymbolTableTest.cpp
index cfc3fe0..4b3545b 100644
--- a/mlir/unittests/IR/SymbolTableTest.cpp
+++ b/mlir/unittests/IR/SymbolTableTest.cpp
@@ -132,4 +132,38 @@ TEST_F(ReplaceAllSymbolUsesTest, StringAttrInFuncOp) {
});
}
+TEST(SymbolOpInterface, Visibility) {
+ DialectRegistry registry;
+ ::test::registerTestDialect(registry);
+ MLIRContext context(registry);
+
+ constexpr static StringLiteral kInput = R"MLIR(
+ "test.overridden_symbol_visibility"() {sym_name = "symbol_name"} : () -> ()
+ )MLIR";
+ OwningOpRef<ModuleOp> module = parseSourceString<ModuleOp>(kInput, &context);
+ auto symOp = cast<SymbolOpInterface>(module->getBody()->front());
+
+ ASSERT_TRUE(symOp.isPrivate());
+ ASSERT_FALSE(symOp.isPublic());
+ ASSERT_FALSE(symOp.isNested());
+ ASSERT_TRUE(symOp.canDiscardOnUseEmpty());
+
+ std::string diagStr;
+ context.getDiagEngine().registerHandler(
+ [&](Diagnostic &diag) { diagStr += diag.str(); });
+
+ std::string expectedDiag;
+ symOp.setPublic();
+ expectedDiag += "'test.overridden_symbol_visibility' op cannot change "
+ "visibility of symbol to public";
+ symOp.setNested();
+ expectedDiag += "'test.overridden_symbol_visibility' op cannot change "
+ "visibility of symbol to nested";
+ symOp.setPrivate();
+ expectedDiag += "'test.overridden_symbol_visibility' op cannot change "
+ "visibility of symbol to private";
+
+ ASSERT_EQ(diagStr, expectedDiag);
+}
+
} // namespace