<div dir="ltr">Hi,<div> </div><div>i am working on a plugin for clang that will show me some custom diagnostics.</div><div><br></div><div>I extended the "Hello World"-plugin PrintFunctionNames so that it emits an errors if it finds a function declaration ( its just a toy plugin )</div><div>Everything works fine if i execute it from command line with clang.</div><div><br></div><div>-------------------------------------------------------------------------------------</div><div>$ clang -Xclang -load -Xclang <pluginpath>/PrintFunctionNames.so -Xclang -add-plugin -Xclang print-fns main.cpp</div><div><div>top-level-decl: "foo"</div><div>/home/incubus/test/clang-plugins/main.cpp:3:1: error: use of undeclared identifier 'foo'</div><div>void foo()</div><div>^</div><div>/home/incubus/test/clang-plugins/main.cpp:12:5: error: use of undeclared identifier 'bar'</div><div>    bar();</div><div>    ^</div><div>top-level-decl: "main"</div><div>/home/incubus/test/clang-plugins/main.cpp:8:1: error: use of undeclared identifier 'main'</div><div>int main(int argc, char** argv){</div><div>^</div><div>3 errors generated.</div></div><div>---------------------------------------------------------------------------------------</div><div><br></div><div>the first and third error are from my plugin and the second is from clang itself.</div><div><br></div><div>Now i want to do the same thing through libclang.</div><div>I am using the vim plugin YouCompleteMe to send all of the flags that were passed to clang, to libclang.</div><div><br></div><div>I followed the path of execution to </div><div>clang_parseTranslationUnit -> clang_parseTranslationUnit2 -> clang_parseTranslationUnit_impl -></div><div> ASTUnit::LoadFromCommandLine -> ASTUnit::LoadFromCompilerInvocation -> ASTUnit::Parse </div><div><br></div><div>were the parsing process is started.</div><div><br></div><div>in FrontendAction::BeginSourceFile  the method FrontendAction::CreateWrappedASTConsumer is called which creates ASTConsumers from the plugins.</div><div>I found out that the Consumer is not created because the FrontendPluginRegistry does not contain any plugins.</div><div>This is due to the fact that the plugin was never loaded.</div><div><br></div><div>I searched the codebase for the loading routines and found out that the only loading is in clang::ExecuteCompilerInvocation.</div><div>I know that clang_parseTranslationUnit is supposed to Parse the translation unit not to execute the whole compiler.</div><div><br></div><div>My question is:</div><div><br></div><div>Is there any way to load the plugin earlier so that it can be executed while parsing?</div><div>Or if it is not possible. Is there some other way to add custom error messages that will be emitted when running clang_parseTranslationUnit?</div><div><br></div><div><br></div><div>Greetings Stefan Kemnitz</div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div> </div><div><br></div><div><br></div><div><br></div><div><br></div></div>