building a custom plugin

Hi LLVM Devs,

I am in the process of building my own plugin for Clang/LLVM in Windows
on Visual Studio. I am having difficulty generating the .dll shared file to use
at compile time. How have the .dlls corresponding to the example plugins
been built?

This works:

clang -fplugin=C:/Users/User/llvm-project/build/Release/bin/PrintFunctionNames.dll -Xclang -plugin -Xclang print-fns test.c

This doesn’t

clang -fplugin=C:/Users/User/llvm-project/build/Release/bin/MyPlugin.dll -Xclang -plugin -Xclang my-plugin test.c

cheers,

Osanne

The code for building the PrintFunctionNames plugin is available here:

https://github.com/llvm/llvm-project/blob/master/clang/examples/PrintFunctionNames/CMakeLists.txt

Michael

Hey LLVM Devs,

I am trying to see if I can use clang plugins to edit
the AST and change the executable output. Any pointers on
whether I’m doing this correctly?

running my plugin:

clang -Xclang -load -Xclang C:\Users\User\llvm-project\build\Release\bin\MyPlugin.dll -Xclang -add-plugin -Xclang my-plugin test.c -o test.exe

how i’m editing the AST (in my Visitor class):
varDecl->setInit(stringLiteral)

Note: The test.exe generated in the above process does not appear to be affected by any changes made to the AST by the plugin

Cheers,

Osanne

Source1.cpp (1.96 KB)