查看 LLVM Demo,创建常量字符串的官方方法是:
常量* consStr = ConstantArray::get(mod->getContext(), "hello", true);
但是,它不起作用!我会得到关于以下的编译错误:
test.cc:860:78: error: no matching function for call to llvm::ConstantArray::get(llvm::LLVMContext&, char*&, bool)’
/remote/vgrnd66/wli/Tools/llvm-3.1/include/llvm/Constants.h:354:20: note: candidate is: static llvm::Constant* llvm::ConstantArray::get(llvm::ArrayType*, llvm::ArrayRef<llvm::Constant*>)
看llvm源码,没有成员函数支持
llvm::ConstantArray::get(llvm::LLVMContext&, char*&, bool)
我正在使用 llvm3.1。
我的代码有什么问题,或者这个构造函数在新源中被删除了吗?
这是 LLVM 源代码的区别。
LLVM2.8
class ConstantArray : public Constant {
// ConstantArray accessors
static Constant *get(const ArrayType *T, const std::vector<Constant*> &V);
static Constant *get(const ArrayType *T, Constant *const *Vals,
unsigned NumVals);
/// This method constructs a ConstantArray and initializes it with a text
/// string. The default behavior (AddNull==true) causes a null terminator to
/// be placed at the end of the array. This effectively increases the length
/// of the array by one (you've been warned). However, in some situations
/// this is not desired so if AddNull==false then the string is copied without
/// null termination.
static Constant *get(LLVMContext &Context, StringRef Initializer,
bool AddNull = true);
}
LLVM3.1
class ConstantArray : public Constant {
public:
// ConstantArray accessors
static Constant *get(ArrayType *T, ArrayRef<Constant*> V);
}
显然,2.8 中有 3 个构造函数,但 3.1 中只有一个用于 ConstantArray 的构造函数。现在我不知道如何创建一个常量字符串...... :(
任何帮助都值得赞赏!
谢谢!