[LLVMdev] getAnalysis*() called on an analysis that was not " "'required' by pass!

john hull johnhull2008 at gmail.com
Tue Mar 4 18:51:15 PST 2008


Hello,

I'd appreciate it if anyone can tell me what the error message means and
point out what I am doing wrong.
Thank you.


I am trying to use the result of the DominatorTree analysis in my ModulePass
class as explained in the section "Writing an LLVM Pass".
http://llvm.org/docs/WritingAnLLVMPass.html#interaction
I called the method "addRequired<DominatorTree>()" in the method
"getAnalysisUsage(AnalysisUsage&)", but I get the following error message.

opt: /usr/local/llvm/llvm/include/llvm/PassAnalysisSupport.h:193:
AnalysisType& llvm::Pass::getAnalysisID(const llvm::PassInfo*) const [with
AnalysisType = llvm::DominatorTree]: Assertion `ResultPass &&
"getAnalysis*() called on an analysis that was not " "'required' by pass!"'
failed.

The following is the command I typed in:
opt -load /usr/local/llvm/install/lib/mymodulepass.so -mymodulepass
<idct.bc> /dev/null

Here are the header and implementation files of my class with just the bare
minimum that produces the error messages.
(MyModulePass.h)
#ifndef MYMODULEPASS_H
#define MYMODULEPASS_H
#include "llvm/Pass.h"

namespace llvm {
        class MyModulePass : public ModulePass {
        public:
                static char ID; // Pass identification, replacement for
typeid
                MyModulePass();
                virtual bool runOnModule(Module &M);
                virtual void getAnalysisUsage(AnalysisUsage &Info) const;

        };

        extern RegisterPass<MyModulePass> X_MyModulePass;
}

#endif

(MyModulePass.cpp)
#include <iostream>
#include "MyModulePass.h"
#include "llvm/Module.h"
#include "llvm/Function.h"
#include "llvm/BasicBlock.h"
#include "llvm/Analysis/Dominators.h"
#include "llvm/Analysis/AliasAnalysis.h"

using namespace llvm;

// ID, register
char llvm::MyModulePass::ID = 0;
RegisterPass<llvm::MyModulePass> llvm::X_MyModulePass("mymodulepass", "My
Module Pass");

MyModulePass::MyModulePass() : ModulePass((intptr_t)&MyModulePass::ID) {
}

bool MyModulePass::runOnModule(Module &m) {
        for (Module::const_iterator f = m.begin(); f != m.end(); ++f)
                DominatorTree &dt = getAnalysis<DominatorTree>();

        return false;
}

void MyModulePass::getAnalysisUsage(AnalysisUsage &info) const {
        info.addRequired<DominatorTree>();
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20080304/e9aab97a/attachment.html>


More information about the llvm-dev mailing list