我从LLVM 3.6.1迁移到LLVM 3.9.0。在LLVMv3.6中,这段代码执行得很好,但在LLVMv3.9中,我发现断言失败:
... include/llvm/IR/Instructions.h:866: static llvm::GetElementPtrInst* llvm::GetElementPtrInst::Create(llvm::Type*, llvm::Value*, llvm::ArrayRef<llvm::Value*>, const llvm::Twine&, llvm::Instruction*): Assertion `PointeeType == cast<PointerType>(Ptr->getType()->getScalarType())->getElementType()' failed.我的代码是:
pOperand = pStore->getValueOperand();
if(!pOperand)
return;
pConstExpr = dyn_cast<ConstantExpr>(pOperand);
if(!pConstExpr)
return;
if(pConstExpr->getOpcode() == Instruction::GetElementPtr)
{
pGEPInst = dyn_cast<GetElementPtrInst>(pConstExpr->getAsInstruction()); // Assertion !!!
if(!pGEPInst)
return;
... other code ...
}编辑:
仅当LLVM-3.9.0的构建类型为DEBUG时,才会出现此问题。发布版本没有这个问题!
发布于 2016-09-30 19:32:51
我找到了我有问题的地方。这是我自己的错误。在LLVM-3.9.0的指令GetElementPtrInst中出现了参数“类型*指针类型”,但LLVM-3.6.1没有出现,这就是我的错误。
当我在LLVM-3.6.1中从源文件生成LLVM IR时,我得到了IR-line:
store i8* getelementptr inbounds ([14 x i8]* @.str1, i32 0, i32 0), i8** %2在LLVM-3.9.0中,这一行:
store i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str1, i32 0, i32 0), i8** %2在此之后,在两个版本中,我将全局变量@.str1更改为@globstr1,并在模块中的任何位置替换它。在LLVM-3.6.1中,此行转换为:
store i8* getelementptr inbounds ([17 x i8]* @globstr1, i32 0, i32 0), i8** %2工作正常,但在LLVM-3.9.0中,这一行转换为:
store i8* getelementptr inbounds ([14 x i8], [17 x i8]* @globstr1, i32 0, i32 0), i8** %2类型14 x i8未更改,此时出现断言故障。
编辑:
此问题仅在build with ASSERTS ( CMAKE的参数-DLLVM_ENABLE_ASSERTIONS=1。对于调试版本,此参数的默认值为ON )。在RELEASE-build中,它不会出现,因为parametr DLLVM_ENABLE_ASSERTIONS的默认值是off (发布版本的默认值)!
https://stackoverflow.com/questions/39617144
复制相似问题