llvm 3.9 ConstantExpr :: getAsInstruction for Instruction :: GetElementPtr get assertion

时间:2016-09-21 12:53:32

标签: llvm assert

我从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时,才会出现此问题。 RELEASE-build没有这个问题!

1 个答案:

答案 0 :(得分:0)

我找到了我遇到问题的地方。这是我自己的错误。在LLVM-3.9.0的GetElementPtrInst指令中出现了参数“Type * PointeeType”,但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] 未更改,并且在此处发生断言失败。

编辑:

仅当使用ASSERTS进行构建时才会出现此问题(对于CMAKE,参数-DLLVM_ENABLE_ASSERTIONS = 1。对于DEBUG构建,此参数默认为ON)。在RELEASE-build中它没有出现,因为参数DLLVM_ENABLE_ASSERTIONS默认是关闭的(默认为RELEASE构建)!

相关问题