CallInst 构造函数是私有的
CallInst constructor is private?
我正在尝试使用LLVM构建代码分析工具的简单版本.我有几个.ll文件,其中包含某些程序的中间LLVM表示形式,并且我正在尝试获取在程序的每个函数中执行的函数调用列表。
这是我的代码,由于我上一篇文章的答案而获得。
void getFunctionCalls(const Module *M)
{
for (const Function &F : *M) {
for (const BasicBlock &BB : F) {
for (const Instruction &I : BB) {
if (CallInst callInst = dyn_cast<CallInst>(I)) {
if (Function *calledFunction = callInst->getCalledFunction()) {
if (calledFunction->getName().startswith("llvm.dbg.declare")) {
// Do something
}
}
}
}
}
}
}
当我编译它时,我收到一个错误说:
home/kike/llvm-3.9.0.src/include/llvm/IR/Instructions.h: In function ‘void getFunctionCalls(const llvm::Module*)’:
/home/kike/llvm-3.9.0.src/include/llvm/IR/Instructions.h:1357:3: error: ‘llvm::CallInst::CallInst(const llvm::CallInst&)’ is private
这意味着 CallInst 构造函数是私有的?在这种情况下,如何获取函数调用列表?
[编辑1]:
我也尝试通过 I 作为参考,如下所示:
void getFunctionCalls(const Module *M)
{
for (const Function &F : *M) {
for (const BasicBlock &BB : F) {
for (const Instruction &I : BB) {
if (CallInst * callInst = dyn_cast<CallInst>(&I)) {
if (Function *calledFunction = callInst->getCalledFunction()) {
if (calledFunction->getName().startswith("llvm.dbg.declare")) {
// Do something
}
}
}
}
}
}
}
我收到此错误:
invalid conversion from ‘llvm::cast_retty<llvm::CallInst, const llvm::Instruction*>::ret_type {aka const llvm::CallInst*}’ to ‘llvm::CallInst*’
CallInst 没有复制构造函数,因为它不是按值传递的。用
const CallInst* callInst = dyn_cast<CallInst>(&I)
而不是
CallInst callInst = dyn_cast<CallInst>(I)
相关文章:
- "error: no matching function for call to"构造函数错误
- C++17复制构造函数,在std::unordereded_map上进行深度复制
- 如果C++类在类方法中具有动态分配,但没有构造函数/析构函数或任何非静态成员,那么它仍然是POD类型吗
- 为什么在没有显式默认构造函数的情况下,将另一个结构封装在联合中作为成员的结构不能编译
- 为什么在C++中使用私有复制构造函数与删除复制构造函数
- 选择要调用的构造函数
- 如何委托派生类使用其父构造函数?
- 构造函数正在调用一个使用当前类类型的函数
- 没有用于初始化C++中的变量模板的匹配构造函数
- 初始化具有非默认构造函数的std::数组项的更好方法
- 当从函数参数中的临时值调用复制构造函数时
- 在c++构造函数中使用随机字符串生成器
- 一对向量构造函数:初始值设定项列表与显式构造
- 从构造函数抛出异常时如何克服内存泄漏
- 我不明白为什么我声明一个空的内部结构并将其传递给构造函数
- 继承:构造函数,初始化C++11中基类的类C数组成员
- 具有默认模板类型的默认构造函数的类型推导
- 使用dynamic_cast和构造函数时出错
- 在c++中使用向量时,如何调用构造函数和析构函数
- CallInst 构造函数是私有的