I want to do static analysis using
libclang from Python.
This involves non-standard C++ attributes like
[[custom::myattr]] that I let Clang convert to
[[clang::annotate("custom::myattr]")]] through the magic of a custom plugin with a
All well and good so far, I can run
clang-15 -Xclang -ast-dump -fsyntax-only -Xclang -load -Xclang libMyPlugin.so test.cpp
On my code and I get for example
-AnnotateAttr 0x562219792be8 <col:7, col:18> "custom::myattr" as part of the AST dump - perfect.
Now I want to use the Python bindings around
libclang to analyze the AST, so I parse my file like this:
import clang.cindex clang.cindex.conf.set_library_file("/usr/lib/llvm-15/lib/libclang.so") index = clang.cindex.Index.create() tu = index.parse("test.cpp", [ "-std=c++2a", "-I/usr/lib/llvm-15/lib/clang/15.0.0/include", "-Xclang", "-load", "-Xclang", "libMyPlugin.so", ] )
and I do not get the annotate-tokens. So I have to assume that the plugin is not loaded (passing a wrong path for the shared library also does not result in an error).
I found some older posts dating back to 2014 to 2016:
but since these are over 5 years old now I am hoping that what I want to do is possible by now, maybe I am just passing the wrong arguments?