Hi,
I have some code that tries to flatten pointers to pointer-sized
integer type. Trying to approximate what resulting IR the compiler
produced when doing an pointer to integer cast in c/c++, I reached to
this snippet of code:
inputLLVMValue is a llvm::Value* that points to some pointer-to-8-word
integer type:
addrIntTypellvm is an 8-word integer type:
llvm::Type* ptrType = llvm::Type::getInt8PtrTy(getLLVMContext());
llvm::Value* vCast =
buildParameters.builder.CreateBitCast( inputLLVMValue, ptrType ,
"castToIntPtrType");
llvm::AllocaInst* alv =
Hive::Compiler::Detail::CreateLLVMTypedEntryBlockAlloca( llvmFunction,
Hive::AST::SymbolName_t("vCast"), ptrType);
llvm::StoreInst* stv =
buildParameters.builder.CreateStore(vCast, alv);
stv->setAlignment(8);
llvm::LoadInst* lv = builder.CreateLoad(alv, "vCastLoad");
llvm::Value* iCast =
buildParameters.builder.CreatePtrToInt( lv, addrIntTypellvm,
"castToIntType");
llvm::AllocaInst* ali =
createLLVMTypedEntryBlockAlloca(llvmFunction,
Hive::AST::SymbolName_t("iCast"),
getAddrIntTypeLLVM(getLLVMContext()));
llvm::StoreInst* sti =
buildParameters.builder.CreateStore(iCast, ali);
sti->setAlignment(8);
llvm::LoadInst* li = builder.CreateLoad(ali, "iCastLoad");
I then use the result of li as any other exprssion
Apparently my code is raising an invalid cast assertion for this test
(Found at IR/Instructions.cpp: CastInst::castIsValid:
return SrcTy->getScalarType()->isPointerTy() &&
DstTy->getScalarType()->isIntegerTy();
when trying to create CreatePtrToInt instruction.
Any idea what might be causing this? What other information could help
me debug this problem?