Crash due to pass not being inserted in the PassManager object

FunctionPass* lower = createLowerSwitchPass();
lower->runOnFunction(F);

My custom pass crashes above. It specifically crashes on getAnalysis call. I’ve enabled assertions when compiling. The log says:

Assertion failed: (Resolver && “Pass has not been inserted into a PassManager object!”), function getAnalysis, file /llvm/include/llvm/PassAnalysisSupport.h, line 231.

Where do I add this pass individually? I know PassManagerBuilder exists. However, that’s more when working with complete pipeline. Ideally, I’d like to explicitly add this to the PassManager object directly and to be able to run using the bin/opt tool.

You can run individually passes with opt option --passes (when using the new pass manager). If your custom pass is outside LLVM, then you need to build it as a pass plugin. In this case, you tell opt using the --load-pass-plugin option where to find the pass plugin.

I hope this helps.

Regards
Kai