取消迭代器时出现Segfault
Segfault when derefing iterator
下面是我的示例。我的完整代码是
#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"通行证示例。当我完全按照示例进行操作时,它运行得很好,但通过上面修改的传递代码,我在运行opt
时得到了segfault。(我使用与"HelloWorld"pass示例中相同的"hello.c"文件作为输入,使用clang编译它,运行make
,并使用opt
调用我的库,与示例中一样。)
是什么导致了我的segfault,有什么方法可以测试/避免它吗?
编辑
我追踪到InstIterator.h:BI = BB->begin();
的61号线。当我的代码到达那个点时,BBs
是非NULL,但BB=BBs->begin()
是NULL。因此,BB
的取消引用导致segfault。为什么BB
为NULL(以及为什么构造函数不检查这一点)的问题仍然存在。
当我的系统进行自动更新并获得几个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
相关文章:
- 使用std::multimap迭代器创建std::list
- 来自 std::list 的迭代器 .end() 按预期返回"0xcdcdcdcdcdcdcdcd"但 .begin()
- C++中带有List类的迭代器Segfault
- 如何在c++迭代器类型中包装std::chrono
- 集合上的输出迭代器:assign和increment迭代器
- Boost Spirit,获取迭代器内部语义动作
- 对于set上的循环-获取next元素迭代器
- 为什么output_editor Concept不需要output_e迭代器标记
- c++17文件系统::recursive_directory迭代器()在mac上没有给出这样的目录,但在windows上
- 使用迭代器时如何访问对象在向量中的位置?
- std::vector::迭代器是否可以合法地作为指针
- 跟随整数索引列表的自定义类迭代器
- 不明白迭代器,引用和指针失效,一个例子
- 我可以使用反向迭代器作为ForwardIt吗
- ESP8266单片机矢量迭代器的C++问题
- 迭代器:如果 '*' 返回元素的引用,为什么删除 *(myList.end()) 会给出 SegFault
- 怪异的迭代器行为+带有无序集的segfault
- 访问迭代器值会导致segfault 11
- 取消迭代器时出现Segfault
- C++-映射迭代器访问导致segfault