InstVisitor usage problem

Hi.All
I had a problem in using llvm::InstVisitor class, my pass is like that:

using namespace llvm;

namespace
{
  class InstVisit : public ModulePass,
            public InstVisitor<InstVisit>
  {
    public :
      static char ID;
      InstVisit():ModulePass(ID){}

      virtual bool runOnModule(Module &M)
      {
        visit(M);
        return false;
      }

      void visitStoreInst(StoreInst &SI)
      {
        errs()<<"a store inst:"<<&SI<<"\n";
      }
  };

   char InstVisit::ID = 0;
   static RegisterPass<InstVisit>
     X("visitInst","visit inst test");
}

then I use
opt -load /home/king/llvm/Release+Asserts/lib/instVisit.so
-visitInst<load.bc> /dev/null
to run the pass. but it appears such errors:

0 opt 0x00000000012700d2 llvm::sys::PrintStackTrace(_IO_FILE*)
+ 34
1 opt 0x000000000126fd29
2 libpthread.so.0 0x00007f9ba0336bd0
3 instVisit.so 0x00007f9b9f33a200
4 opt 0x00000000012081ef
llvm::MPPassManager::runOnModule(llvm::Module&) + 655
5 opt 0x0000000001209f7f
llvm::PassManagerImpl::run(llvm::Module&) + 223
6 opt 0x000000000057e1ac main + 3772
7 libc.so.6 0x00007f9b9f55eea5 __libc_start_main + 245
8 opt 0x000000000058fe65
Stack dump:
0. Program arguments: opt -load
/home/king/llvm/Release+Asserts/lib/instVisit.so -visitInst
1. Running pass 'visit inst test' on module '<stdin>'.
Segmentation fault (core dumped)

the load.c is :

int main() {
  int x, y, z;

  x = 12;
  y = x + 22; /* load value of x that was just stored */
  z = y + 33; /* load value of y that was just stored */
  return z;
}

there is no stdin in the program .but why it says "Running pass 'visit inst
test' on module '<stdin>'."

Thank You!

-JinHuang

The opt invocation looks weird to me. I would expect something like:

opt -load /home/king/llvm/Release+Asserts/lib/instVisit.so -visitInst load.bc

Cheers,

Sorry, I copied it from the shell, so the format may be not right! I used the opt command just like you wrote!

Thanks.

-JinHuang

I found that this error is caused by the visit(M) ,once I delete this. It runs without errors.
And, I found that some of my previous pass also can not run(didn’t happen before) normally with the same error. If I delete the code which will reference the Module &M, the error disappear.
That is very strange. What’s wrong with that?