How to run a new pass by clang

Hi all,
I know how to invoke a new pass by opt, but when I’m trying to use clang to load and run a new function pass, the pass can’t be executed, the pass is just like the hello pass in llvm/lib/Transforms/Hello created. the command line i used in below, how can i invoke my new pass :frowning:

…/llvm-project-llvmorg-15.0.7/build/bin/clang -Xclang -load -Xclang …/llvm-project-llvmorg-15.0.7/build/lib/ -O1 test.c -o test


you might want to use -fpass-plugin=/absolute/path/to/

Thank for your reply, I tried using clang-14.0.0 with the legacy PM, and it worked.

…/llvm-project-llvmorg-14.0.0/build/bin/clang -flegacy-pass-manager -Xclang -load -Xclang $path-to-so test.c

But clang-14.0.0 with new PM, it has the same problem with clang-15, I also tried the way you suggested, also failed. Maybe there are some problems with myself, but fortunately, I have found a feasible method so far.
Thank you again for your reply.

The -fpass-plugin=... I suggested was only for new PassManager Pass plugins. That flag can not be used to load Pass plugins for legacy PassManager. (In case you don’t know plugins for new / legacy Passes are completely different)

YES, thank u :slight_smile:

I am using clang 16.0.0 and I used the following command to generate the output of with -fpass-plugin=...for new pass manager plugin.
I used the following command to generate sum.ll file.

_path_to_llvm/_build/bin/clang -Xclang -load -Xclang _path_to_llvm/_build/lib/ -fpass-plugin=_path_to_llvm/_build/lib/ -S -O1 -emit-llvm sum.c -o sum.ll

But it is not generating the modified output .ll file. What would be the reason?Is there any mistake in this command?

It really depends on how MyPass was written. Maybe it wasn’t inserting the Pass at the right position in the pipeline.


These are the flags for legacy Passes. I don’t think mixing flags for legacy and new PassManager will work.

Thank you so much.I will revisit MyPass.cpp and positioning pass.