Require ModulePass from within FunctionPass

I have a function pass MyFunctionPass with:

getAnalysisUsage(llvm::AnalysisUsage &AU) const {
  AU.addRequired<MyModulePass>();
  AU.setPreservesAll();
}

And on MyFunctionPass::doInitialization() i do a getAnalysis<MyModulePass>()

However when i run MyFunctionPass in opt i get:

Assertion `ResultPass && "getAnalysis*() called on an analysis that was not " "'required' by pass!"' failed.

Why is this happening? Am i not supposed to require a ModulePass from a FunctionPass?

I still have this problem. I would appreciate any help or directions to look for relevant info.

Thanks.

The comment for doInitialization() is:

  /// doInitialization - Virtual method overridden by subclasses to do
  /// any necessary initialization before any pass is run.

Because it happens before any pass in the the pipeline is executed, you can’t get an Analysis from there.