我试图将类型[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's LLVM release_70 branch,它只是经过稍微修改的LLVM 7.1.0库。