[llvm-dev] ModulePass cannot be registered as EarlyAsPossible

Son Tuan VU via llvm-dev llvm-dev at lists.llvm.org
Tue Jun 12 06:46:13 PDT 2018

Hello all,

I've followed the example in
https://github.com/CompilerTeaching/SimplePass/blob/master/SimplePass.cc in
order to create a custom pass.

The pass needs to be added before any transformation, so I used
EP_EarlyAsPossible extension point to register it.  Furthermore, I need to
access to every GlobalVariable in the IR, so my pass has to be a
ModulePass, like this:

  struct MyPass : public ModulePass {
     static char ID;
     MyPass(): ModulePass(ID) {}
     virtual bool runOnModule(Module &M) {...}

However, every time I try to access to the Module object M inside
runOnModule(), clang just crashes.  Even a debug message like *outs() <<
M.getName() << '\n';* would cause a segfault. So am I doing something
wrong, like EP_EarlyAsPossible is really not to be used with ModulePasses,
or is this rather a bug?

In case this is not a bug, what would be the best way to manipulate an IR
Module as it is coming right out of the frontend?

Thanks for your help,

Son Tuan Vu
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20180612/8276709b/attachment.html>

More information about the llvm-dev mailing list