[Mlir-commits] [llvm] [mlir] [mlir] fix Undefined behavior in CastInfo::castFailed with From=<MLIRinterface> (PR #87145)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Thu Jul 11 22:29:28 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:
I have fixed and eliminated compiler warnings `returning reference to local temporary object`, as well as fixed the issue of `OpInterface` crashing when converting to `Op`. There seems to be an environmental issue with i`ree-llvm-sandbox` on my local machine, and I am planning to submit this fix for this project to try. Currently, I need to refine this fix again.
https://github.com/llvm/llvm-project/pull/87145
More information about the Mlir-commits
mailing list