C++ llvm:将i8*类型值强制转换为双类型值

C++ llvm:将i8*类型值强制转换为双类型值,c++,llvm,C++,Llvm,我有一个char指针(Type::getInt8PtrTy(Context))并试图将保存该指针的值(换句话说是字符串)转换为double类型(Type::getDoubleTy(Context))。我尝试的方式是: Value* stringValue = ... // Value which type Type::getInt8PtrTy(Context) auto doubleValue = CastInst::CreatePointerCast(stringValue, Type::ge

我有一个char指针(Type::getInt8PtrTy(Context))并试图将保存该指针的值(换句话说是字符串)转换为double类型(Type::getDoubleTy(Context))。我尝试的方式是:

Value* stringValue = ... // Value which type Type::getInt8PtrTy(Context)
auto doubleValue = CastInst::CreatePointerCast(stringValue, Type::getDoubleTy(Context), Builder.GetInsertBlock());
AllocaInst *alloca = .. //alloc memory for element which type is Type::getDoubleTy(Context)
Builder.CreateStore(doubleValue, alloca);
问题是,当我试图使用外部C函数(printf)打印doubleValue时,看起来我得到了地址,但没有得到doubleValue。换句话说,我想写一些代码,这些代码和C原子函数一样。 我用的是C++ API。
我将非常感谢您的回答。

atoi
不会简单地将变量强制转换为其他类型。它实际上通过某种算法将字符串值转换为整数

如果要执行相同的操作,必须在位代码中包含一个实现该算法的函数,然后在指针上使用
call
指令获取
double

如果确实要将字符串的数据解释为双精度,请使用
bitcast
将指针从
i8*
转换为
double*
,然后使用
load
指令