gpt4 book ai didi

c++ - 取消引用迭代器时出现段错误

转载 作者:太空宇宙 更新时间:2023-11-04 13:39:12 26 4
gpt4 key购买 nike

我正在按照示例 here .我的完整代码是

#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 时遇到了段错误。(我使用与“HelloWorld”传递示例中相同的“hello.c”文件作为输入,使用 clang 编译它,运行 make 并使用 opt 就像在示例中一样。)

是什么导致了我的段错误,有什么方法可以测试它/避免它吗?

编辑

我将段错误追踪到 InstIterator.h 的第 61 行: BI = BB->开始();。当我的代码到达那个点时,BBs 是非 NULL,但是 BB=BBs->begin() 是 NULL。因此,对 BB 的取消引用会导致段错误。 为什么 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

关于c++ - 取消引用迭代器时出现段错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28396040/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com