[Mlir-commits] [mlir] [mlir] fix Undefined behavior in CastInfo::castFailed with From=<MLIRinterface> (PR #87145)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Sun Jul 7 20:32:08 PDT 2024
================
@@ -84,3 +87,40 @@ TEST(InterfaceTest, TestImplicitConversion) {
typeA = typeB;
EXPECT_EQ(typeA, typeB);
}
+
+TEST(OperationInterfaceTest, CastOpToInterface) {
+ DialectRegistry registry;
+ MLIRContext ctx;
+
+ const char *ir = R"MLIR(
+ func.func @map(%arg : tensor<1xi64>) {
+ %0 = arith.constant dense<[10]> : tensor<1xi64>
+ %1 = arith.addi %arg, %0 : tensor<1xi64>
+ return
+ }
+ )MLIR";
+
+ registry.insert<func::FuncDialect, arith::ArithDialect>();
+ ctx.appendDialectRegistry(registry);
+ OwningOpRef<ModuleOp> module = parseSourceString<ModuleOp>(ir, &ctx);
+ Operation &op = cast<func::FuncOp>(module->front()).getBody().front().front();
+
+ OpAsmOpInterface interface = llvm::cast<OpAsmOpInterface>(op);
+
+ bool constantOp =
+ llvm::TypeSwitch<OpAsmOpInterface, bool>(interface)
+ .Case<VectorUnrollOpInterface, arith::ConstantOp>([&](auto op) {
+ return std::is_same_v<decltype(op), arith::ConstantOp>;
+ });
+
+ EXPECT_TRUE(constantOp);
+
+ EXPECT_FALSE(llvm::isa<VectorUnrollOpInterface>(interface));
+ EXPECT_FALSE(llvm::dyn_cast<VectorUnrollOpInterface>(interface));
+
+ EXPECT_TRUE(llvm::isa<InferTypeOpInterface>(interface));
+ EXPECT_TRUE(llvm::dyn_cast<InferTypeOpInterface>(interface));
+
+ EXPECT_TRUE(llvm::isa<OpAsmOpInterface>(interface));
+ EXPECT_TRUE(llvm::dyn_cast<OpAsmOpInterface>(interface));
+}
----------------
lipracer wrote:
If there is no such change, the test case will fail to compile on my local machine. (gcc (Ubuntu 9.4.0-1ubuntu1~20.04.3) 9.4.0). @ingomueller-net Can you help me check if there are any differences between the tests here and the ones you provided in the [issue](https://github.com/llvm/llvm-project/issues/86647)?
https://github.com/llvm/llvm-project/pull/87145
More information about the Mlir-commits
mailing list