2015-02-08 78 views
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(以及为什么构造函数不检查)仍然存在。

+0

你能否提供你正在运行该过程的IR?你使用的是什么LLVM版本? – 2015-02-09 05:57:57

+0

LLVM 3.5.1,按照链接中的“HelloWord”关卡的指示,使用由clang 3.5.0生成的'hello.bc'文件。 – crockeea 2015-02-09 13:53:03

回答

0

当我的系统进行自动更新并获得几个llvm-3.5软件包(今天)的新版本时,此问题已得到解决。此前,opt --version返回

LLVM version 3.5 

Optimized build. 
Built Mar 23 2014 (21:41:30). 
Default target: x86_64-pc-linux-gnu 
Host CPU: corei7 

现在返回

LLVM version 3.5.0 

Optimized build. 
Built Jan 27 2015 (00:14:48). 
Default target: x86_64-pc-linux-gnu 
Host CPU: corei7