about summary refs log tree commit diff homepage
diff options
context:
space:
mode:
authorLukas Zaoral <lzaoral@redhat.com>2020-09-10 17:24:49 +0200
committerCristian Cadar <c.cadar@imperial.ac.uk>2020-12-04 20:35:47 +0000
commit3ba7dedcd9864a4fb91a0937ca3f570de2d12a62 (patch)
treea4100c6029ee0a5f96d316161b2d5481b5a2ac49
parent30336015ff88298f38841efa1e0dd120e71f2f67 (diff)
downloadklee-3ba7dedcd9864a4fb91a0937ca3f570de2d12a62.tar.gz
llvm11: Composite and Sequential types were removed
See:
https://reviews.llvm.org/D75660
https://reviews.llvm.org/D75661
-rw-r--r--lib/Core/Executor.cpp54
-rw-r--r--lib/Core/Executor.h5
-rw-r--r--lib/Core/GetElementPtrTypeIterator.h10
3 files changed, 43 insertions, 26 deletions
diff --git a/lib/Core/Executor.cpp b/lib/Core/Executor.cpp
index c0d29272..fac36b71 100644
--- a/lib/Core/Executor.cpp
+++ b/lib/Core/Executor.cpp
@@ -3270,6 +3270,25 @@ void Executor::updateStates(ExecutionState *current) {
   removedStates.clear();
 }
 
+template <typename SqType, typename TypeIt>
+void Executor::computeOffsetsSeqTy(KGEPInstruction *kgepi,
+                                   ref<ConstantExpr> &constantOffset,
+                                   uint64_t index, const TypeIt it) {
+  const auto *sq = cast<SqType>(*it);
+  uint64_t elementSize =
+      kmodule->targetData->getTypeStoreSize(sq->getElementType());
+  const Value *operand = it.getOperand();
+  if (const 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.emplace_back(index, elementSize);
+  }
+}
+
 template <typename TypeIt>
 void Executor::computeOffsets(KGEPInstruction *kgepi, TypeIt ib, TypeIt ie) {
   ref<ConstantExpr> constantOffset =
@@ -3282,33 +3301,16 @@ 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 (const auto set = dyn_cast<SequentialType>(*ii)) {
-      uint64_t elementSize = 
-        kmodule->targetData->getTypeStoreSize(set->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));
-      }
 #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));
-      }
+    } 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
+    } else if (isa<SequentialType>(*ii)) {
+      computeOffsetsSeqTy<SequentialType>(kgepi, constantOffset, index, ii);
 #endif
     } else
       assert("invalid type" && 0);
diff --git a/lib/Core/Executor.h b/lib/Core/Executor.h
index 30d1dd92..1614a0f9 100644
--- a/lib/Core/Executor.h
+++ b/lib/Core/Executor.h
@@ -449,6 +449,11 @@ private:
   /// bindModuleConstants - Initialize the module constant table.
   void bindModuleConstants();
 
+  template <typename SqType, typename TypeIt>
+  void computeOffsetsSeqTy(KGEPInstruction *kgepi,
+                           ref<ConstantExpr> &constantOffset, uint64_t index,
+                           const TypeIt it);
+
   template <typename TypeIt>
   void computeOffsets(KGEPInstruction *kgepi, TypeIt ib, TypeIt ie);
 
diff --git a/lib/Core/GetElementPtrTypeIterator.h b/lib/Core/GetElementPtrTypeIterator.h
index cdbc36bc..87de667d 100644
--- a/lib/Core/GetElementPtrTypeIterator.h
+++ b/lib/Core/GetElementPtrTypeIterator.h
@@ -65,8 +65,12 @@ class generic_gep_type_iterator
     llvm::Type *operator*() const { return CurTy; }
 
     llvm::Type *getIndexedType() const {
+#if LLVM_VERSION_CODE >= LLVM_VERSION(11, 0)
+      return llvm::GetElementPtrInst::getTypeAtIndex(CurTy, getOperand());
+#else
       llvm::CompositeType *CT = cast<llvm::CompositeType>(CurTy);
       return CT->getTypeAtIndex(getOperand());
+#endif
     }
 
     // This is a non-standard operator->.  It allows you to call methods on the
@@ -76,8 +80,14 @@ class generic_gep_type_iterator
     llvm::Value *getOperand() const { return asValue(*OpIt); }
 
     generic_gep_type_iterator& operator++() {   // Preincrement
+#if LLVM_VERSION_CODE >= LLVM_VERSION(11, 0)
+      if (isa<llvm::StructType>(CurTy) || isa<llvm::ArrayType>(CurTy) ||
+          isa<llvm::VectorType>(CurTy)) {
+        CurTy = llvm::GetElementPtrInst::getTypeAtIndex(CurTy, getOperand());
+#else
       if (llvm::CompositeType *CT = dyn_cast<llvm::CompositeType>(CurTy)) {
         CurTy = CT->getTypeAtIndex(getOperand());
+#endif
 #if LLVM_VERSION_CODE >= LLVM_VERSION(4, 0)
       } else if (auto ptr = dyn_cast<llvm::PointerType>(CurTy)) {
         CurTy = ptr->getElementType();