<div dir="ltr">Hi folks,<div><br></div><div>I wanted to add a function pass inside the compiler. Therefore, I added the following pass skeleton to the compiler (which works for an out-of-tree compilation):</div><div><br></div><div><div>#include "llvm/Pass.h"</div><div><br></div><div>using namespace llvm;</div><div><br></div><div>namespace {</div><div>  class FooPass : public FunctionPass {</div><div>  public:</div><div>    static char ID; </div><div><br></div><div>    FooPass() : FunctionPass(ID) {</div><div>    }</div><div><br></div><div>    bool runOnFunction(Function &F) override;</div><div>  };</div><div>}</div><div><br></div><div>bool FooPass::runOnFunction(Function &F) {</div><div>  return false;</div><div>}</div><div><br></div><div>char FooPass::ID = 0;</div><div>INITIALIZE_PASS_BEGIN(FooPass, "foo",</div><div>                      "My little Foo Pass", false, false)</div><div>INITIALIZE_PASS_END(FooPass, "foo",</div><div>                    "My little Foo Pass", false, false)</div><div><br></div><div>FunctionPass *llvm::createFooPass() {</div><div>  return new FooPass();</div><div>}</div></div><div><br></div><div>However, when compiling the compiler, the initialization of the pass seems not to be working because I get the following error messages:</div><div><br></div><div><div>In file included from /home/work/gitprojects/llvm/include/llvm/Pass.h:377:0,</div><div>                 from /home/work/gitprojects/llvm/lib/Transforms/ancoder/foo_pass.cpp:1:</div><div>/home/work/gitprojects/llvm/include/llvm/PassSupport.h:81:63: error: ‘void llvm::initializeFooPassPass(llvm::PassRegistry&)’ should have been declared inside ‘llvm’</div><div>   void llvm::initialize##passName##Pass(PassRegistry &Registry) { \</div><div>                                                               ^</div><div>/home/work/gitprojects/llvm/lib/Transforms/ancoder/foo_pass.cpp:24:1: note: in expansion of macro ‘INITIALIZE_PASS_END’</div><div> INITIALIZE_PASS_END(FooPass, "foo",</div><div> ^</div><div>/home/work/gitprojects/llvm/lib/Transforms/ancoder/foo_pass.cpp:27:35: error: ‘llvm::FunctionPass* llvm::createFooPass()’ should have been declared inside ‘llvm’</div><div> FunctionPass *llvm::createFooPass() {</div><div>                                   ^</div></div><div><br></div><div>I already looked up other passes within the compiler, but do not see the difference why it is working there and not here.</div><div><br></div><div>Can someone guide me how to fix this error?</div><div><br></div><div>Thanks and Cheers,</div><div>Max</div></div>