about summary refs log tree commit diff homepage
diff options
context:
space:
mode:
authorJiri Slaby <jirislaby@gmail.com>2017-06-08 13:25:56 +0200
committerMartinNowack <martin.nowack@gmail.com>2018-09-18 10:36:36 +0100
commit06cf93da0c60a9a8f48c94db7fa1d8b2cc755eef (patch)
treea5f2aae289977e977f127d8598046b1546e0419d
parentb2659ec04a9814718736ad960635a9a28edd6078 (diff)
downloadklee-06cf93da0c60a9a8f48c94db7fa1d8b2cc755eef.tar.gz
llvm4: PointerType is not SequentialType
So handle the type specially whenever needed.

Signed-off-by: Jiri Slaby <jirislaby@gmail.com>
-rw-r--r--include/klee/util/GetElementPtrTypeIterator.h4
-rw-r--r--lib/Core/Executor.cpp20
2 files changed, 21 insertions, 3 deletions
diff --git a/include/klee/util/GetElementPtrTypeIterator.h b/include/klee/util/GetElementPtrTypeIterator.h
index 5fb9f4ec..ce380bc0 100644
--- a/include/klee/util/GetElementPtrTypeIterator.h
+++ b/include/klee/util/GetElementPtrTypeIterator.h
@@ -78,6 +78,10 @@ class generic_gep_type_iterator
     generic_gep_type_iterator& operator++() {   // Preincrement
       if (llvm::CompositeType *CT = dyn_cast<llvm::CompositeType>(CurTy)) {
         CurTy = CT->getTypeAtIndex(getOperand());
+#if LLVM_VERSION_CODE >= LLVM_VERSION(4, 0)
+      } else if (auto 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 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<SequentialType>(*ii);
+    } else if (const auto set = dyn_cast<SequentialType>(*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<PointerType>(*ii)) {
+      auto elementSize =
+        kmodule->targetData->getTypeStoreSize(ptr->getElementType());
+      auto operand = ii.getOperand();
+      if (auto c = dyn_cast<Constant>(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();