2017-06-08 12:15:29 +00:00
|
|
|
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>
|
|
|
|
---
|
2017-08-17 12:28:29 +00:00
|
|
|
include/klee/util/GetElementPtrTypeIterator.h | 4 ++++
|
2017-06-08 12:15:29 +00:00
|
|
|
lib/Core/Executor.cpp | 22 +++++++++++++++++++---
|
|
|
|
lib/Core/ExecutorUtil.cpp | 17 ++++++++++++++---
|
2017-08-17 12:28:29 +00:00
|
|
|
3 files changed, 37 insertions(+), 6 deletions(-)
|
2017-06-08 12:15:29 +00:00
|
|
|
|
|
|
|
diff --git a/include/klee/util/GetElementPtrTypeIterator.h b/include/klee/util/GetElementPtrTypeIterator.h
|
2017-08-17 12:28:29 +00:00
|
|
|
index 5fb9f4ec5c2f..bf7cb6ff0bea 100644
|
2017-06-08 12:15:29 +00:00
|
|
|
--- a/include/klee/util/GetElementPtrTypeIterator.h
|
|
|
|
+++ b/include/klee/util/GetElementPtrTypeIterator.h
|
2017-08-17 12:28:29 +00:00
|
|
|
@@ -78,6 +78,10 @@ class generic_gep_type_iterator
|
|
|
|
generic_gep_type_iterator& operator++() { // Preincrement
|
|
|
|
if (llvm::CompositeType *CT = dyn_cast<llvm::CompositeType>(CurTy)) {
|
2017-06-08 12:15:29 +00:00
|
|
|
CurTy = CT->getTypeAtIndex(getOperand());
|
|
|
|
+#if LLVM_VERSION_CODE >= LLVM_VERSION(4, 0)
|
2017-08-17 12:28:29 +00:00
|
|
|
+ } else if (llvm::PointerType *ptr = dyn_cast<llvm::PointerType>(CurTy)) {
|
2017-06-08 12:15:29 +00:00
|
|
|
+ CurTy = ptr->getElementType();
|
|
|
|
+#endif
|
|
|
|
} else {
|
|
|
|
CurTy = 0;
|
|
|
|
}
|
|
|
|
diff --git a/lib/Core/Executor.cpp b/lib/Core/Executor.cpp
|
2017-10-10 13:09:53 +00:00
|
|
|
index 08474ae700ac..5a88f1ae3180 100644
|
2017-06-08 12:15:29 +00:00
|
|
|
--- a/lib/Core/Executor.cpp
|
|
|
|
+++ b/lib/Core/Executor.cpp
|
2017-10-10 13:09:53 +00:00
|
|
|
@@ -2520,8 +2520,7 @@ void Executor::computeOffsets(KGEPInstruction *kgepi, TypeIt ib, TypeIt ie) {
|
2017-06-08 12:15:29 +00:00
|
|
|
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();
|
2017-10-10 13:09:53 +00:00
|
|
|
@@ -2535,7 +2534,24 @@ void Executor::computeOffsets(KGEPInstruction *kgepi, TypeIt ib, TypeIt ie) {
|
2017-06-08 12:15:29 +00:00
|
|
|
} 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
|
2017-08-17 12:28:29 +00:00
|
|
|
index 53f4c5b85754..6d18e07425c5 100644
|
2017-06-08 12:15:29 +00:00
|
|
|
--- a/lib/Core/ExecutorUtil.cpp
|
|
|
|
+++ b/lib/Core/ExecutorUtil.cpp
|
2017-08-17 12:28:29 +00:00
|
|
|
@@ -199,8 +199,7 @@ namespace klee {
|
2017-06-08 12:15:29 +00:00
|
|
|
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 =
|
2017-08-17 12:28:29 +00:00
|
|
|
evalConstant(cast<Constant>(ii.getOperand()), ki);
|
2017-06-08 12:15:29 +00:00
|
|
|
unsigned elementSize =
|
2017-08-17 12:28:29 +00:00
|
|
|
@@ -209,7 +208,19 @@ namespace klee {
|
2017-06-08 12:15:29 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
--
|
2017-10-10 13:09:53 +00:00
|
|
|
2.14.2
|
2017-06-08 12:15:29 +00:00
|
|
|
|