Cannot use function pass in a module pass

Hi. I'm trying to implement a module pass which can be dynamically
loaded by `opt` (against up-to-date llvm from svn).
Despite what the tutorial
(http://llvm.org/docs/WritingAnLLVMPass.html) states in my module pass
I cannot perform getAnalysis and fetch the function pass result.
When trying to do so `opt` fails with the following mesage:

[***@*** ***]$ opt -load ~/llvm/Debug+Asserts/lib/MyPassLibrary.so
-mymodulepass < input.bc >/dev/null
MyModulePass::runOnModule
MyFunctionPass::runOnFunction(process)
opt: /***/llvm/include/llvm/MyFunctionPass.h:241: AnalysisType&
llvm::Pass::getAnalysisID(llvm::AnalysisID, llvm::Function&) [with
AnalysisType = {anonymous}::MyFunctionPass, llvm::AnalysisID = const
void*]: Assertion `ResultPass && "Unable to find requested analysis
info"' failed.
0 opt 0x0000000000dbcd86
1 opt 0x0000000000dbcb82
2 libpthread.so.0 0x0000003b8f00eeb0
3 libc.so.6 0x0000003b8e835285 gsignal + 53
4 libc.so.6 0x0000003b8e836b9b abort + 379
5 libc.so.6 0x0000003b8e82dc0e
6 libc.so.6 0x0000003b8e82dcb2
7 MyPassLibrary.so 0x00007fb2989ce7e8
8 MyPassLibrary.so 0x00007fb2989ce59f
9 MyPassLibrary.so 0x00007fb2989ce401
10 opt 0x0000000000d39af7
llvm::MPPassManager::runOnModule(llvm::Module&) + 453
11 opt 0x0000000000d39ff8
llvm::PassManagerImpl::run(llvm::Module&) + 130
12 opt 0x0000000000d3a3ff llvm::PassManager::run(llvm::Module&) + 39
13 opt 0x00000000008c6803 main + 4561
14 libc.so.6 0x0000003b8e82139d __libc_start_main + 237
15 opt 0x00000000008b7b69
Stack dump:
0. Program arguments: opt -load
/***/llvm/Debug+Asserts/lib/MyPassLibrary.so -mymodulepass
1. Running pass 'My module pass' on module '<stdin>'.
Aborted

Hi Alexey,

Hi. I'm trying to implement a module pass which can be dynamically
loaded by `opt` (against up-to-date llvm from svn).
Despite what the tutorial
(http://llvm.org/docs/WritingAnLLVMPass.html) states in my module pass
I cannot perform getAnalysis and fetch the function pass result.
When trying to do so `opt` fails with the following mesage:

RegisterPass takes an "is_analysis" argument that you should probably set
to true when registering your analysis pass.

Ciao, Duncan.

Hi. I'm trying to implement a module pass which can be dynamically
loaded by `opt` (against up-to-date llvm from svn).
Despite what the tutorial
(http://llvm.org/docs/WritingAnLLVMPass.html) states in my module pass
I cannot perform getAnalysis and fetch the function pass result.
When trying to do so `opt` fails with the following mesage:

This may not be your problem, but in older versions of LLVM, you cannot call getAnalysis<FunctionPassName>(F) if F is a function with no body. You need to do something like:

if (!(F->isDeclaration())) {
     getAnalysis<FunctionPassName>(F);
     ...
}

-- John T.

Thanks, John.
There were a couple of function declarations in the module, and
'getAnalysis' failed for those.

By the way, what do you mean by "in older versions of LLVM"? I'm quite
sure I was using the latest llvm trunk.

Thanks, John.
There were a couple of function declarations in the module, and
'getAnalysis' failed for those.

By the way, what do you mean by "in older versions of LLVM"? I'm quite
sure I was using the latest llvm trunk.

What I meant was that I am using an older version of LLVM; in that older version (LLVM 2.7), trying to run a FunctionPass on a function without a body triggers an assertion. It is possible that newer versions of LLVM don't trigger the assertion, but I tend to suspect that the behavior has remained unchanged.

-- John T.