2015-02-08 80 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