我偶然发现了一些非常奇怪的东西——我正在写一个 LLVM 模块 Pass。我遍历模块的所有函数,然后遍历每个非声明函数的所有循环,并将指向循环的指针存储在std::vector
. 这是来源:
virtual bool runOnModule(Module& Mod){
std::vector<Loop*> loops;
// first gather all loop info
for(Module::iterator f = Mod.begin(), fend = Mod.end(); f != fend; ++f){
if (!(*f).isDeclaration()){
LoopInfo& LI = getAnalysis<LoopInfo>(*f);
for(LoopInfo::iterator l = LI.begin(), lend = LI.end(); l != lend; ++l){
loops.push_back(*l);
}
}
}
for (auto& l: loops) errs () << *l << " ";
}
现在,如果我运行它,我会遇到运行时错误 - 它无法打印循环,不知何故我正在执行空指针取消引用或某事。有任何想法吗?