From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Zaoral?= Date: Sat, 5 Mar 2022 16:50:36 +0100 Subject: llvm14: PointerType::getElementType() was deprecated Git-repo: https://github.com/lzaoral/klee#llvm14 Git-commit: 6caf7f74dd5aedcb39ade5f33a34673d3b6b091f Patch-mainline: no References: llvm 14 ... for LLVM 14 in [1] and has already been removed from the LLVM 15 branch in [2]. Some changes are only temporary to silence the warning though, as Type::getPointerElementType() is planned to be removed as well. [3] [1] https://reviews.llvm.org/D117885/new/ [2] https://github.com/llvm/llvm-project/commit/d593cf7 [3] https://llvm.org/docs/OpaquePointers.html#migration-instructions Signed-off-by: Jiri Slaby --- include/klee/Module/KCallable.h | 5 +++++ include/klee/Module/KModule.h | 4 ++++ lib/Core/Executor.cpp | 30 ++++++++++++---------------- lib/Core/Executor.h | 2 +- lib/Core/ExternalDispatcher.cpp | 3 +-- lib/Core/GetElementPtrTypeIterator.h | 4 ++-- lib/Module/FunctionAlias.cpp | 6 ++---- 7 files changed, 28 insertions(+), 26 deletions(-) diff --git a/include/klee/Module/KCallable.h b/include/klee/Module/KCallable.h index bf8b17ea..e25fb5b5 100644 --- a/include/klee/Module/KCallable.h +++ b/include/klee/Module/KCallable.h @@ -32,6 +32,7 @@ public: CallableKind getKind() const { return Kind; } virtual llvm::StringRef getName() const = 0; + virtual llvm::FunctionType *getFunctionType() const = 0; virtual llvm::PointerType *getType() const = 0; virtual llvm::Value *getValue() = 0; @@ -55,6 +56,10 @@ public: llvm::StringRef getName() const override { return name; } + llvm::FunctionType *getFunctionType() const override { + return value->getFunctionType(); + } + llvm::PointerType *getType() const override { return value->getType(); } llvm::Value *getValue() override { return value; } diff --git a/include/klee/Module/KModule.h b/include/klee/Module/KModule.h index 71fe8a0a..ca6d2b22 100644 --- a/include/klee/Module/KModule.h +++ b/include/klee/Module/KModule.h @@ -64,6 +64,10 @@ namespace klee { llvm::StringRef getName() const override { return function->getName(); } + llvm::FunctionType *getFunctionType() const override { + return function->getFunctionType(); + } + llvm::PointerType *getType() const override { return function->getType(); } llvm::Value *getValue() override { return function; } diff --git a/lib/Core/Executor.cpp b/lib/Core/Executor.cpp index 42405982..661198e7 100644 --- a/lib/Core/Executor.cpp +++ b/lib/Core/Executor.cpp @@ -710,7 +710,7 @@ void Executor::allocateGlobalObjects(ExecutionState &state) { for (const GlobalVariable &v : m->globals()) { std::size_t globalObjectAlignment = getAllocationAlignment(&v); - Type *ty = v.getType()->getElementType(); + Type *ty = v.getValueType(); std::uint64_t size = 0; if (ty->isSized()) size = kmodule->targetData->getTypeStoreSize(ty); @@ -2420,10 +2420,9 @@ void Executor::executeInstruction(ExecutionState &state, KInstruction *ki) { } if (f) { - const FunctionType *fType = - dyn_cast(cast(f->getType())->getElementType()); + const FunctionType *fType = f->getFunctionType(); const FunctionType *fpType = - dyn_cast(cast(fp->getType())->getElementType()); + dyn_cast(fp->getType()->getPointerElementType()); // special case the call with a bitcast case if (fType != fpType) { @@ -3324,13 +3323,14 @@ void Executor::updateStates(ExecutionState *current) { removedStates.clear(); } -template +template void Executor::computeOffsetsSeqTy(KGEPInstruction *kgepi, ref &constantOffset, uint64_t index, const TypeIt it) { - const auto *sq = cast(*it); + assert(it->getNumContainedTypes() == 1 && + "Sequential type must contain one subtype"); uint64_t elementSize = - kmodule->targetData->getTypeStoreSize(sq->getElementType()); + kmodule->targetData->getTypeStoreSize(it->getContainedType(0)); const Value *operand = it.getOperand(); if (const Constant *c = dyn_cast(operand)) { ref index = @@ -3355,12 +3355,9 @@ void Executor::computeOffsets(KGEPInstruction *kgepi, TypeIt ib, TypeIt ie) { uint64_t addend = sl->getElementOffset((unsigned) ci->getZExtValue()); constantOffset = constantOffset->Add(ConstantExpr::alloc(addend, Context::get().getPointerWidth())); - } else if (isa(*ii)) { - computeOffsetsSeqTy(kgepi, constantOffset, index, ii); - } else if (isa(*ii)) { - computeOffsetsSeqTy(kgepi, constantOffset, index, ii); - } else if (isa(*ii)) { - computeOffsetsSeqTy(kgepi, constantOffset, index, ii); + } else if (isa(*ii) || isa(*ii) || + isa(*ii)) { + computeOffsetsSeqTy(kgepi, constantOffset, index, ii); } else assert("invalid type" && 0); index++; @@ -4611,10 +4608,9 @@ size_t Executor::getAllocationAlignment(const llvm::Value *allocSite) const { alignment = GO->getAlignment(); if (const GlobalVariable *globalVar = dyn_cast(GO)) { // All GlobalVariables's have pointer type - llvm::PointerType *ptrType = - dyn_cast(globalVar->getType()); - assert(ptrType && "globalVar's type is not a pointer"); - type = ptrType->getElementType(); + assert(globalVar->getType()->isPointerTy() && + "globalVar's type is not a pointer"); + type = globalVar->getValueType(); } else { type = GO->getType(); } diff --git a/lib/Core/Executor.h b/lib/Core/Executor.h index 279d8bee..4b88567a 100644 --- a/lib/Core/Executor.h +++ b/lib/Core/Executor.h @@ -450,7 +450,7 @@ private: /// bindModuleConstants - Initialize the module constant table. void bindModuleConstants(); - template + template void computeOffsetsSeqTy(KGEPInstruction *kgepi, ref &constantOffset, uint64_t index, const TypeIt it); diff --git a/lib/Core/ExternalDispatcher.cpp b/lib/Core/ExternalDispatcher.cpp index 7a0d8e14..d286bea9 100644 --- a/lib/Core/ExternalDispatcher.cpp +++ b/lib/Core/ExternalDispatcher.cpp @@ -284,8 +284,7 @@ Function *ExternalDispatcherImpl::createDispatcher(KCallable *target, argI64sp->getType()->getPointerElementType(), argI64sp, "args"); // Get the target function type. - FunctionType *FTy = cast( - cast(target->getType())->getElementType()); + FunctionType *FTy = target->getFunctionType(); // Each argument will be passed by writing it into gTheArgsP[i]. unsigned i = 0, idx = 2; diff --git a/lib/Core/GetElementPtrTypeIterator.h b/lib/Core/GetElementPtrTypeIterator.h index 89606a0a..54fe6a29 100644 --- a/lib/Core/GetElementPtrTypeIterator.h +++ b/lib/Core/GetElementPtrTypeIterator.h @@ -88,8 +88,8 @@ class generic_gep_type_iterator if (llvm::CompositeType *CT = dyn_cast(CurTy)) { CurTy = CT->getTypeAtIndex(getOperand()); #endif - } else if (auto ptr = dyn_cast(CurTy)) { - CurTy = ptr->getElementType(); + } else if (llvm::isa(CurTy)) { + CurTy = CurTy->getPointerElementType(); } else { CurTy = 0; } diff --git a/lib/Module/FunctionAlias.cpp b/lib/Module/FunctionAlias.cpp index a98b74fb..aa80b35d 100644 --- a/lib/Module/FunctionAlias.cpp +++ b/lib/Module/FunctionAlias.cpp @@ -135,10 +135,8 @@ bool FunctionAliasPass::runOnModule(Module &M) { const FunctionType *FunctionAliasPass::getFunctionType(const GlobalValue *gv) { const Type *type = gv->getType(); - while (type->isPointerTy()) { - const PointerType *ptr = cast(type); - type = ptr->getElementType(); - } + while (type->isPointerTy()) + type = type->getPointerElementType(); return cast(type); } -- 2.35.3