2016-09-21 30 views
0

我從LLVM 3.6.1遷移到LLVM 3.9.0。在LLVMv3.6這段代碼執行罰款,但在LLVMv3.9我斷言失敗:llvm 3.9 ConstantExpr :: getAsInstruction for Instruction :: GetElementPtr get assertion

... 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沒有這個問題!

+0

你能提供IR嗎? – Joky

+0

事實上,它沒有在發佈中抱怨只是隱藏了一個可能的錯誤,你會在某個時候遇到麻煩。 – Joky

回答

0

我發現我遇到問題。這是我自己的錯誤。在LLVM-3.9.0的指令GetElementPtrInst中出現了參數「Type * PointeeType」,但LLVM-3.6.1它的參數不是,那是我的錯誤。

當LLVM-3.6.1我從源文件生成LLVM IR,我得到了IR-行:

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×6-18]沒有改變,並在這個地方發生斷言失敗。

編輯:

出現此問題僅當與構建ASSERTS(參數-DLLVM_ENABLE_ASSERTIONS = 1的CMake這parametr默認爲ON調試版本)。在RELEASE-構建它不會出現,因爲參數DLLVM_ENABLE_ASSERTIONS默認是關閉的(默認爲RELEASE構建)!