1
我遵循示例here。我的完整代码是Segref当删除迭代器时
#include "llvm/IR/Function.h"
#include "llvm/Pass.h"
#include "llvm/IR/InstIterator.h"
using namespace llvm;
namespace {
struct Hello2 : public FunctionPass {
static char ID; // Pass identification, replacement for typeid
Hello2() : FunctionPass(ID) {}
bool runOnFunction(Function &F) override {
inst_iterator iter = inst_begin(F); // causes a segfault
return false;
}
};
}
char Hello2::ID = 0;
static RegisterPass<Hello2> Y("hello2", "Hello World Pass");
继“HelloWorld”传递示例解释here。当我完全按照例子,它运行良好,但通过上面修改的密码,当我运行opt
时,出现段错误。 (我使用输入相同的“hello.c的”文件中的“HelloWorld”通过实例,铿锵编译它,运行make
和打电话给我用opt
库就像在例子)
什么导致我的段错误,并有任何方法来测试它/避免它?
EDIT
我跟踪的段错误,以线61 InstIterator.h的:BI = BB->begin();
。当我的代码达到该点时,BBs
是非NULL,但BB=BBs->begin()
是NULL。因此BB
的解除引起段错误。 这个问题为什么BB
是NULL(以及为什么构造函数不检查)仍然存在。
你能否提供你正在运行该过程的IR?你使用的是什么LLVM版本? – 2015-02-09 05:57:57
LLVM 3.5.1,按照链接中的“HelloWord”关卡的指示,使用由clang 3.5.0生成的'hello.bc'文件。 – crockeea 2015-02-09 13:53:03