[llvm-dev] Compiling a simple pass skeleton inside LLVM fails

Justin Bogner via llvm-dev llvm-dev at lists.llvm.org
Wed Apr 12 09:00:03 PDT 2017


Max Muster via llvm-dev <llvm-dev at lists.llvm.org> writes:
> 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):
>
> #include "llvm/Pass.h"
>
> using namespace llvm;
>
> namespace {
>   class FooPass : public FunctionPass {
>   public:
>     static char ID;
>
>     FooPass() : FunctionPass(ID) {
>     }
>
>     bool runOnFunction(Function &F) override;
>   };
> }
>
> bool FooPass::runOnFunction(Function &F) {
>   return false;
> }
>
> char FooPass::ID = 0;
> INITIALIZE_PASS_BEGIN(FooPass, "foo",
>                       "My little Foo Pass", false, false)
> INITIALIZE_PASS_END(FooPass, "foo",
>                     "My little Foo Pass", false, false)
>
> FunctionPass *llvm::createFooPass() {
>   return new FooPass();
> }
>
> However, when compiling the compiler, the initialization of the pass seems
> not to be working because I get the following error messages:
>
> In file included from /home/work/gitprojects/llvm/include/llvm/Pass.h:377:0,
>                  from
> /home/work/gitprojects/llvm/lib/Transforms/ancoder/foo_pass.cpp:1:
> /home/work/gitprojects/llvm/include/llvm/PassSupport.h:81:63: error: ‘void
> llvm::initializeFooPassPass(llvm::PassRegistry&)’ should have been declared
> inside ‘llvm’
>    void llvm::initialize##passName##Pass(PassRegistry &Registry) { \
>                                                                ^
> /home/work/gitprojects/llvm/lib/Transforms/ancoder/foo_pass.cpp:24:1: note:
> in expansion of macro ‘INITIALIZE_PASS_END’
>  INITIALIZE_PASS_END(FooPass, "foo",
>  ^
> /home/work/gitprojects/llvm/lib/Transforms/ancoder/foo_pass.cpp:27:35:
> error: ‘llvm::FunctionPass* llvm::createFooPass()’ should have been
> declared inside ‘llvm’
>  FunctionPass *llvm::createFooPass() {
>                                    ^
>
> I already looked up other passes within the compiler, but do not see the
> difference why it is working there and not here.
>
> Can someone guide me how to fix this error?

I think you're missing a forward declaration of the pass initializer in
the llvm namespace. See the declarations in "llvm/InitializePasses.h"
for where in-tree pass initializers are declared.


More information about the llvm-dev mailing list