about summary refs log tree commit diff homepage
diff options
context:
space:
mode:
-rw-r--r--include/klee/Module/KCallable.h6
-rw-r--r--include/klee/Module/KModule.h4
-rw-r--r--lib/Core/Executor.cpp29
-rw-r--r--lib/Core/Executor.h2
-rw-r--r--lib/Core/ExternalDispatcher.cpp3
-rw-r--r--lib/Core/GetElementPtrTypeIterator.h4
-rw-r--r--lib/Module/FunctionAlias.cpp6
7 files changed, 25 insertions, 29 deletions
diff --git a/include/klee/Module/KCallable.h b/include/klee/Module/KCallable.h
index bf8b17ea..6fe8419d 100644
--- a/include/klee/Module/KCallable.h
+++ b/include/klee/Module/KCallable.h
@@ -32,7 +32,7 @@ public:
   CallableKind getKind() const { return Kind; }
 
   virtual llvm::StringRef getName() const = 0;
-  virtual llvm::PointerType *getType() const = 0;
+  virtual llvm::FunctionType *getFunctionType() const = 0;
   virtual llvm::Value *getValue() = 0;
 
   virtual ~KCallable() = default;
@@ -55,7 +55,9 @@ public:
 
   llvm::StringRef getName() const override { return name; }
 
-  llvm::PointerType *getType() const override { return value->getType(); }
+  llvm::FunctionType *getFunctionType() const override {
+    return value->getFunctionType();
+  }
 
   llvm::Value *getValue() override { return value; }
 
diff --git a/include/klee/Module/KModule.h b/include/klee/Module/KModule.h
index 71fe8a0a..e2dc71d1 100644
--- a/include/klee/Module/KModule.h
+++ b/include/klee/Module/KModule.h
@@ -64,7 +64,9 @@ namespace klee {
 
     llvm::StringRef getName() const override { return function->getName(); }
 
-    llvm::PointerType *getType() const override { return function->getType(); }
+    llvm::FunctionType *getFunctionType() const override {
+      return function->getFunctionType();
+    }
 
     llvm::Value *getValue() override { return function; }
 
diff --git a/lib/Core/Executor.cpp b/lib/Core/Executor.cpp
index 013f01c2..d644d647 100644
--- a/lib/Core/Executor.cpp
+++ b/lib/Core/Executor.cpp
@@ -740,7 +740,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);
@@ -2441,10 +2441,9 @@ void Executor::executeInstruction(ExecutionState &state, KInstruction *ki) {
     }
 
     if (f) {
-      const FunctionType *fType = 
-        dyn_cast<FunctionType>(cast<PointerType>(f->getType())->getElementType());
+      const FunctionType *fType = f->getFunctionType();
       const FunctionType *fpType =
-        dyn_cast<FunctionType>(cast<PointerType>(fp->getType())->getElementType());
+          dyn_cast<FunctionType>(fp->getType()->getPointerElementType());
 
       // special case the call with a bitcast case
       if (fType != fpType) {
@@ -3345,13 +3344,14 @@ void Executor::updateStates(ExecutionState *current) {
   removedStates.clear();
 }
 
-template <typename SqType, typename TypeIt>
+template <typename TypeIt>
 void Executor::computeOffsetsSeqTy(KGEPInstruction *kgepi,
                                    ref<ConstantExpr> &constantOffset,
                                    uint64_t index, const TypeIt it) {
-  const auto *sq = cast<SqType>(*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<Constant>(operand)) {
     ref<ConstantExpr> index =
@@ -3376,12 +3376,8 @@ 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<ArrayType>(*ii)) {
-      computeOffsetsSeqTy<ArrayType>(kgepi, constantOffset, index, ii);
-    } else if (isa<VectorType>(*ii)) {
-      computeOffsetsSeqTy<VectorType>(kgepi, constantOffset, index, ii);
-    } else if (isa<PointerType>(*ii)) {
-      computeOffsetsSeqTy<PointerType>(kgepi, constantOffset, index, ii);
+    } else if (ii->isArrayTy() || ii->isVectorTy() || ii->isPointerTy()) {
+      computeOffsetsSeqTy(kgepi, constantOffset, index, ii);
     } else
       assert("invalid type" && 0);
     index++;
@@ -4712,10 +4708,9 @@ size_t Executor::getAllocationAlignment(const llvm::Value *allocSite) const {
     alignment = GO->getAlignment();
     if (const GlobalVariable *globalVar = dyn_cast<GlobalVariable>(GO)) {
       // All GlobalVariables's have pointer type
-      llvm::PointerType *ptrType =
-          dyn_cast<llvm::PointerType>(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 21d0d081..c821b987 100644
--- a/lib/Core/Executor.h
+++ b/lib/Core/Executor.h
@@ -449,7 +449,7 @@ private:
   /// bindModuleConstants - Initialize the module constant table.
   void bindModuleConstants();
 
-  template <typename SqType, typename TypeIt>
+  template <typename TypeIt>
   void computeOffsetsSeqTy(KGEPInstruction *kgepi,
                            ref<ConstantExpr> &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<FunctionType>(
-      cast<PointerType>(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..23bda1f0 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<llvm::CompositeType>(CurTy)) {
         CurTy = CT->getTypeAtIndex(getOperand());
 #endif
-      } else if (auto ptr = dyn_cast<llvm::PointerType>(CurTy)) {
-        CurTy = ptr->getElementType();
+      } else if (CurTy->isPointerTy()) {
+        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<PointerType>(type);
-    type = ptr->getElementType();
-  }
+  while (type->isPointerTy())
+    type = type->getPointerElementType();
   return cast<FunctionType>(type);
 }