aboutsummaryrefslogtreecommitdiff
path: root/mlir/unittests/IR/SymbolTableTest.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'mlir/unittests/IR/SymbolTableTest.cpp')
-rw-r--r--mlir/unittests/IR/SymbolTableTest.cpp34
1 files changed, 34 insertions, 0 deletions
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