c++ - AllocaInst 的使用示例 : LLVM

标签 c++ llvm llvm-clang llvm-ir

我是 LLVM 的新手,我想通过示例了解 AllocaInst 的正确用法。我尝试在线搜索,甚至 llvm 网页也没有正确的示例。 下面是我要执行的代码补丁。

string temp =(dyn_cast<ConstantInt>operand0))->getValue()).toString(10,true);
Type* A = IntegerType::getInt32Ty(F.getContext());
string name = "t"+to_string(++counter);
AllocaInst* variable = new AllocaInst(A,NULL,4,name,&*inst);

当我运行它时,我会得到一个错误:

error:no matching function for call to 'llvm::AllocaInst::AllocaInst(llvm::Type*&, NULL, int, std::string&, llvm::Instruction*)' AllocaInst* variable = new AllocaInst(A,NULL,4,name,&*inst);

我想知道如何在 AllcaInst 中提供地址位置。任何帮助将不胜感激。

最佳答案

你不能用这种方式初始化一个数组。您的代码的问题是数组大小。 AllocaInst 期望数组大小有一个 llvm::Value*,即,大小必须存在于 IR 中。要获得常量 4,您必须使用 ConstantInt::get 在 IR 中创建常量整数值。 ConstantInt* 可以提供给 AllocaInst 构造函数。

关于c++ - AllocaInst 的使用示例 : LLVM,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45799933/

相关文章:

gcc - 为什么 LLVM 项目使用 GCC Headers

c++ - 将特定的 gcc 警告变成错误

c++ - 将 std::enable_if 从参数移动到模板参数

java - Android NDK、JNI、蓝牙 : Designing the Android Application which is having C++ source code/library with Bluetooth APIs/methods , 使用 JNI

c++ - vector::clear 在 libc++ 中用于简单可破坏的类型

segmentation-fault - 在 Rust 中调用 llvm_sys 的 LLVMCreateTargetMachine 生成目标文件时出现段错误

c++ - 调用模板基类的模板函数

c++ - 为 llvm::ConstantInt 设置值

compiler-errors - unique_ptr 作为类成员和移动语义无法使用 clang 编译

objective-c - 静态分析和 "create rule"