LLVM 无法将数组类型强制转换为常量数组
LLVM Can't cast array type to ConstantArray
我正在尝试将类型为[3 x double]
的数组强制转换为ConstantArray
,以最终将底层类型从double
更改为float
。但每当我尝试选角时,它都会失败,我一直想不出原因。
正在运行的过程中的代码片段(经过编辑以添加更多信息(:
CallInst& inst; //passed in by function arg
CallInst* oldCall = &inst;
Constant *constant = dyn_cast<Constant>(oldCall->getOperand(1)->stripPointerCasts());
errs() << "Operand is: " << *constant->getOperand(0) << "n";
errs() << "Operand type: " << *constant->getOperand(0)->getType() << "n";
ConstantArray *constantArray = cast<ConstantArray>(constant->getOperand(0));
输出:
Operand is: [3 x double] [double 2.100000e+00, double 2.200000e+00, double 2.300000e+00]
Operand type: [3 x double]
opt: /include/llvm/Support/Casting.h:255: typename llvm::cast_retty<X, Y*>::ret_type llvm::cast(Y*)
[with X = llvm::ConstantArray; Y = llvm::Value; typename llvm::cast_retty<X, Y*>::ret_type =
llvm::ConstantArray*]: Assertion `isa<X>(Val) && "cast<Ty>() argument of incompatible type!"' failed.
可以看出,常量中的操作数是一个数组类型。当尝试强制转换时,由于强制转换的潜在性质(我认为是?(,它看到了Value
,但仍然无法认为它们是兼容的。有人知道为什么会这样吗?
注意:这是使用flang的LLVM release_70分支,它只是一个稍微修改过的LLVM 7.1.0库。
不能将数组强制转换为其他任何类型,包括不同的数组(AIUI,因为强制转换规则是特定于语言的(。通常的方法是投射一个指针,类似这样。
auto c = CastInst::Create(CastInst::BitCast,
sourcePointerToDoubleArray,
ArrayType::get(Type::getFloatTy(), 3)->getPointerto(),
"funny_little_ast",
targetBasicBlock);
还有一个ConstantExpr::getPointerCast()
。这两者都只是简单地重新解释了你指向的比特
相关文章:
- 如何在C++中将数组转换为矢量指针
- 将C++中的数组转换为字符串
- NLOHMANN 的 JSON 库将数组转换为结构向量
- 将 int 数组转换为 std::vector<int*>
- 在nlohmann json中,如何将嵌套对象的数组转换为嵌套结构的向量
- 无法在 Arduino 中uint8_t数组转换为无符号长整型数组
- 将字节数组转换为带有字节序问题的指针
- 使用 stbi_write_png,如何将 0 和 1 的矩形字节数组转换为单色 png 文件?
- 将字符数组转换为时间结构
- 将字节数组转换为多维数组
- 可视化 如何在C++中将字符数组转换为 FILE 类型
- 在 C++ 中将整数数组转换为位集表示形式的最佳方法?
- C++如何将字符数组转换为字节向量(向量<byte>)
- 将字符数组转换为结构时出现问题. 结构的字符数组变量溢出
- 无法将字符数组转换为包含 utf-8 字符的字符串
- 如何使用 C++将 2D RGB 数组转换为 dds 文件?
- 如何将字符串指针数组转换为字符串类型的智能指针向量?
- 将 int 数组转换为带有小数C++的双精度数组
- 使用 .data() 将字符数组转换为 std::string 不会转换整个数组
- 将字符数组转换为整数值