OBS-URL: https://build.opensuse.org/package/show/devel:tools:statica/klee?expand=0&rev=24
109 lines
4.6 KiB
Diff
109 lines
4.6 KiB
Diff
From: Jiri Slaby <jirislaby@gmail.com>
|
|
Date: Thu, 8 Jun 2017 13:25:56 +0200
|
|
Subject: llvm: PointerType is not SequentialType in LLVM 4
|
|
Patch-mainline: no
|
|
|
|
So handle the type specially whenever needed.
|
|
|
|
Signed-off-by: Jiri Slaby <jirislaby@gmail.com>
|
|
---
|
|
include/klee/util/GetElementPtrTypeIterator.h | 5 +++++
|
|
lib/Core/Executor.cpp | 22 +++++++++++++++++++---
|
|
lib/Core/ExecutorUtil.cpp | 17 ++++++++++++++---
|
|
3 files changed, 38 insertions(+), 6 deletions(-)
|
|
|
|
diff --git a/include/klee/util/GetElementPtrTypeIterator.h b/include/klee/util/GetElementPtrTypeIterator.h
|
|
index 2d145cd67f14..b551d772eaac 100644
|
|
--- a/include/klee/util/GetElementPtrTypeIterator.h
|
|
+++ b/include/klee/util/GetElementPtrTypeIterator.h
|
|
@@ -93,6 +93,11 @@ namespace klee {
|
|
if (LLVM_TYPE_Q llvm::CompositeType *CT =
|
|
dyn_cast<llvm::CompositeType>(CurTy)) {
|
|
CurTy = CT->getTypeAtIndex(getOperand());
|
|
+#if LLVM_VERSION_CODE >= LLVM_VERSION(4, 0)
|
|
+ } else if (LLVM_TYPE_Q llvm::PointerType *ptr =
|
|
+ dyn_cast<llvm::PointerType>(CurTy)) {
|
|
+ CurTy = ptr->getElementType();
|
|
+#endif
|
|
} else {
|
|
CurTy = 0;
|
|
}
|
|
diff --git a/lib/Core/Executor.cpp b/lib/Core/Executor.cpp
|
|
index 4a0239dace49..fd5cb5e4e751 100644
|
|
--- a/lib/Core/Executor.cpp
|
|
+++ b/lib/Core/Executor.cpp
|
|
@@ -2648,8 +2648,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<SequentialType>(*ii);
|
|
+ } else if (const SequentialType *set = dyn_cast<SequentialType>(*ii)) {
|
|
uint64_t elementSize =
|
|
kmodule->targetData->getTypeStoreSize(set->getElementType());
|
|
Value *operand = ii.getOperand();
|
|
@@ -2663,7 +2662,24 @@ 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 PointerType *ptr = dyn_cast<PointerType>(*ii)) {
|
|
+ uint64_t elementSize =
|
|
+ kmodule->targetData->getTypeStoreSize(ptr->getElementType());
|
|
+ Value *operand = ii.getOperand();
|
|
+ if (Constant *c = dyn_cast<Constant>(operand)) {
|
|
+ ref<ConstantExpr> index =
|
|
+ evalConstant(c)->SExt(Context::get().getPointerWidth());
|
|
+ ref<ConstantExpr> 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();
|
|
diff --git a/lib/Core/ExecutorUtil.cpp b/lib/Core/ExecutorUtil.cpp
|
|
index b91b5deec173..a63b891bf925 100644
|
|
--- a/lib/Core/ExecutorUtil.cpp
|
|
+++ b/lib/Core/ExecutorUtil.cpp
|
|
@@ -102,8 +102,7 @@ namespace klee {
|
|
addend = ConstantExpr::alloc(sl->getElementOffset((unsigned)
|
|
ci->getZExtValue()),
|
|
Context::get().getPointerWidth());
|
|
- } else {
|
|
- const SequentialType *set = cast<SequentialType>(*ii);
|
|
+ } else if (const SequentialType *set = dyn_cast<SequentialType>(*ii)) {
|
|
ref<ConstantExpr> index =
|
|
evalConstant(cast<Constant>(ii.getOperand()));
|
|
unsigned elementSize =
|
|
@@ -112,7 +111,19 @@ namespace klee {
|
|
index = index->ZExt(Context::get().getPointerWidth());
|
|
addend = index->Mul(ConstantExpr::alloc(elementSize,
|
|
Context::get().getPointerWidth()));
|
|
- }
|
|
+#if LLVM_VERSION_CODE >= LLVM_VERSION(4, 0)
|
|
+ } else if (const PointerType *ptr = dyn_cast<PointerType>(*ii)) {
|
|
+ ref<ConstantExpr> index =
|
|
+ evalConstant(cast<Constant>(ii.getOperand()));
|
|
+ unsigned elementSize =
|
|
+ kmodule->targetData->getTypeStoreSize(ptr->getElementType());
|
|
+
|
|
+ index = index->ZExt(Context::get().getPointerWidth());
|
|
+ addend = index->Mul(ConstantExpr::alloc(elementSize,
|
|
+ Context::get().getPointerWidth()));
|
|
+#endif
|
|
+ } else
|
|
+ assert("invalid type" && 0);
|
|
|
|
base = base->Add(addend);
|
|
}
|
|
--
|
|
2.13.1
|
|
|