Custom Pragmas Clang Tools


I have been reading some articles [1, 2] regarding how to implement handlers for custom pragmas. Nonetheless, in those posts Clang source code has to be modified. I am developing an Clang tool out-of-tree, so I do not want to make a custom version of Clang. I was just wondering if it is possible to build a custom handler for pragmas out-of-tree or if I have to tackle another approach maybe using annotations (?) or any other workaround? Basically I want to use pragmas for indicating loops of interest for the tool in C/C++ code.



You can create your own executable that creates a CompilerInstance and
adds pragma handles to it.

Example shown here:


That is exactly what I was looking for.
Thank you so much.


FYI: There’s also an example plugin that adds a pragma handler: