[Mlir-commits] [mlir] [mlir][python] C++ API demo (PR #71133)

Maksim Levental llvmlistbot at llvm.org
Mon Nov 6 13:19:55 PST 2023


================
@@ -607,11 +607,13 @@ if(MLIR_INCLUDE_TESTS)
     ROOT_DIR "${MLIR_SOURCE_DIR}/test/python/lib"
     SOURCES
       PythonTestModule.cpp
+      PythonTestPass.cpp
     PRIVATE_LINK_LIBS
       LLVMSupport
     EMBED_CAPI_LINK_LIBS
       MLIRCAPIPythonTestDialect
   )
+  set_source_files_properties(${MLIR_SOURCE_DIR}/test/python/lib/PythonTestPass.cpp PROPERTIES COMPILE_FLAGS -fno-rtti)
----------------
makslevental wrote:

By default, anything linked into a C extension module that's being built using [pybind cmake helpers](https://github.com/llvm/llvm-project/blob/92233062c17590d3157bdc6db430fcdfc54312fe/mlir/cmake/modules/AddMLIRPython.cmake#L639-L643). The problem is `PythonPass`, which inherits from `mlir::Pass`, will then "depend" on the RTTI for `mlir::Pass`[^1]. So you can make this example work by compiling just `PythonPass.cpp` without RTTI[^2].

[^1]: See [this godbolt](https://godbolt.org/z/1GWTEzbGT) where the typeinfo for B dereferences the typeinfo for A _even though that typeinfo doesn't appear anywhere_.
[^2]: Or you can make this example work by building MLIR with `ENABLE_RTTI=ON` but that's a non-starter for us (right...?).

https://github.com/llvm/llvm-project/pull/71133


More information about the Mlir-commits mailing list