[llvm-dev] Compiling a simple pass skeleton inside LLVM fails (original) (raw)

Max Muster via llvm-dev llvm-dev at lists.llvm.org
Wed Apr 12 02:20:42 PDT 2017


Hi folks,

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?

Thanks and Cheers, Max -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20170412/df6415b7/attachment.html>



More information about the llvm-dev mailing list