From 06cf93da0c60a9a8f48c94db7fa1d8b2cc755eef Mon Sep 17 00:00:00 2001 From: Jiri Slaby Date: Thu, 8 Jun 2017 13:25:56 +0200 Subject: llvm4: PointerType is not SequentialType So handle the type specially whenever needed. Signed-off-by: Jiri Slaby --- lib/Core/Executor.cpp | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) (limited to 'lib/Core') diff --git a/lib/Core/Executor.cpp b/lib/Core/Executor.cpp index 1a5b7b9d..04fd6941 100644 --- a/lib/Core/Executor.cpp +++ b/lib/Core/Executor.cpp @@ -2621,8 +2621,7 @@ 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 { - const SequentialType *set = cast(*ii); + } else if (const auto set = dyn_cast(*ii)) { uint64_t elementSize = kmodule->targetData->getTypeStoreSize(set->getElementType()); Value *operand = ii.getOperand(); @@ -2636,7 +2635,22 @@ void Executor::computeOffsets(KGEPInstruction *kgepi, TypeIt ib, TypeIt ie) { } else { kgepi->indices.push_back(std::make_pair(index, elementSize)); } - } +#if LLVM_VERSION_CODE >= LLVM_VERSION(4, 0) + } else if (const auto ptr = dyn_cast(*ii)) { + auto elementSize = + kmodule->targetData->getTypeStoreSize(ptr->getElementType()); + auto operand = ii.getOperand(); + if (auto c = dyn_cast(operand)) { + auto index = evalConstant(c)->SExt(Context::get().getPointerWidth()); + auto addend = index->Mul(ConstantExpr::alloc(elementSize, + Context::get().getPointerWidth())); + constantOffset = constantOffset->Add(addend); + } else { + kgepi->indices.push_back(std::make_pair(index, elementSize)); + } +#endif + } else + assert("invalid type" && 0); index++; } kgepi->offset = constantOffset->getZExtValue(); -- cgit 1.4.1