使用来自其他通行证的通行证时出现LLVM错误

时间:2016-12-27 02:06:09

标签: c++ compiler-construction llvm static-analysis

这是我的LLVM Pass:

#include <llvm/IR/Function.h>
#include <llvm/Pass.h>
#include <llvm/Support/raw_ostream.h>
#include <llvm/Analysis/MemoryDependenceAnalysis.h>

using namespace llvm;

namespace
{
    struct MemDepend : public FunctionPass
    {
        static char ID;
        MemDepend() : FunctionPass(ID){}

        virtual bool runOnFunction(Function &F)
        {
            MemoryDependenceAnalysis *MDA = &getAnalysis<MemoryDependenceAnalysis>();
            return false;
        }

        virtual void getAnalysisUsage(AnalysisUsage &AU) const
        {
              AU.setPreservesAll();
        }
    };
}

char MemDepend::ID = 0;
static RegisterPass<MemDepend> X("memdep", "Memory Pass", false, false);

当我尝试编译它时,收到以下错误:

  

在/usr/local/include/llvm/Pass.h:388:0中包含的文件中,
  来自/home/ahmad/Codes/LLVM/MyPass/myPass.cpp:3:   /usr/local/include/llvm/PassAnalysisSupport.h:实例化'AnalysisType&amp; llvm :: Pass :: getAnalysis()const [with AnalysisType = llvm :: MemoryDe​​pendenceAnalysis]':   /home/ahmad/Codes/LLVM/MyPass/myPass.cpp:18:79:从这里要求   /usr/local/include/llvm/PassAnalysisSupport.h:223:37:错误:没有匹配函数来调用'llvm :: Pass :: getAnalysisID(void *(*)())const'      return getAnalysisID(&amp; AnalysisType :: ID);                                        ^

如何编译它而没有错误?

1 个答案:

答案 0 :(得分:1)

我相信规范的方式是

MemoryDependenceResults &MDA =
    getAnalysis<MemoryDependenceWrapperPass>().getMemDep();

同样,

AU.addRequired<MemoryDependenceWrapperPass>();

您可以在LLVM代码库中找到上述示例。