about summary refs log tree commit diff homepage
path: root/lib/Core
diff options
context:
space:
mode:
authorJulian Büning <julian.buening@comsys.rwth-aachen.de>2023-06-11 15:45:26 +0200
committerMartinNowack <2443641+MartinNowack@users.noreply.github.com>2023-06-11 19:19:28 +0100
commitdab1c0fa376771be1c3cdd5b8d564484755907dd (patch)
tree11182051745c007adcf1b2e0db976d261520f927 /lib/Core
parentf3a4b343b09a431f708e74870ce1a1021c94c93a (diff)
downloadklee-dab1c0fa376771be1c3cdd5b8d564484755907dd.tar.gz
SpecialFunctionHandler: use std::array for handlerInfo
Diffstat (limited to 'lib/Core')
-rw-r--r--lib/Core/SpecialFunctionHandler.cpp46
-rw-r--r--lib/Core/SpecialFunctionHandler.h31
2 files changed, 8 insertions, 69 deletions
diff --git a/lib/Core/SpecialFunctionHandler.cpp b/lib/Core/SpecialFunctionHandler.cpp
index 332e4b56..b2d85710 100644
--- a/lib/Core/SpecialFunctionHandler.cpp
+++ b/lib/Core/SpecialFunctionHandler.cpp
@@ -36,6 +36,7 @@ DISABLE_WARNING_DEPRECATED_DECLARATIONS
 #include "llvm/IR/Module.h"
 DISABLE_WARNING_POP
 
+#include <array>
 #include <cerrno>
 #include <sstream>
 
@@ -69,11 +70,11 @@ cl::opt<bool>
 // especially things like realloc which have complicated semantics
 // w.r.t. forking. Among other things this makes delayed query
 // dispatch easier to implement.
-static SpecialFunctionHandler::HandlerInfo handlerInfo[] = {
-#define add(name, handler, ret) { name, \
+static constexpr std::array handlerInfo = {
+#define add(name, handler, ret) SpecialFunctionHandler::HandlerInfo{ name, \
                                   &SpecialFunctionHandler::handler, \
                                   false, ret, false }
-#define addDNR(name, handler) { name, \
+#define addDNR(name, handler) SpecialFunctionHandler::HandlerInfo{ name, \
                                 &SpecialFunctionHandler::handler, \
                                 true, false, false }
   addDNR("__assert_rtn", handleAssertFail),
@@ -82,7 +83,7 @@ static SpecialFunctionHandler::HandlerInfo handlerInfo[] = {
   addDNR("_assert", handleAssert),
   addDNR("abort", handleAbort),
   addDNR("_exit", handleExit),
-  { "exit", &SpecialFunctionHandler::handleExit, true, false, true },
+  SpecialFunctionHandler::HandlerInfo{ "exit", &SpecialFunctionHandler::handleExit, true, false, true },
   addDNR("klee_abort", handleAbort),
   addDNR("klee_silent_exit", handleSilentExit),
   addDNR("klee_report_error", handleReportError),
@@ -147,40 +148,12 @@ static SpecialFunctionHandler::HandlerInfo handlerInfo[] = {
 #undef add
 };
 
-SpecialFunctionHandler::const_iterator SpecialFunctionHandler::begin() {
-  return SpecialFunctionHandler::const_iterator(handlerInfo);
-}
-
-SpecialFunctionHandler::const_iterator SpecialFunctionHandler::end() {
-  // NULL pointer is sentinel
-  return SpecialFunctionHandler::const_iterator(0);
-}
-
-SpecialFunctionHandler::const_iterator& SpecialFunctionHandler::const_iterator::operator++() {
-  ++index;
-  if ( index >= SpecialFunctionHandler::size())
-  {
-    // Out of range, return .end()
-    base=0; // Sentinel
-    index=0;
-  }
-
-  return *this;
-}
-
-int SpecialFunctionHandler::size() {
-	return sizeof(handlerInfo)/sizeof(handlerInfo[0]);
-}
-
 SpecialFunctionHandler::SpecialFunctionHandler(Executor &_executor) 
   : executor(_executor) {}
 
 void SpecialFunctionHandler::prepare(
     std::vector<const char *> &preservedFunctions) {
-  unsigned N = size();
-
-  for (unsigned i=0; i<N; ++i) {
-    HandlerInfo &hi = handlerInfo[i];
+  for (auto &hi : handlerInfo) {
     Function *f = executor.kmodule->module->getFunction(hi.name);
 
     // No need to create if the function doesn't exist, since it cannot
@@ -201,12 +174,9 @@ void SpecialFunctionHandler::prepare(
 }
 
 void SpecialFunctionHandler::bind() {
-  unsigned N = size();
-
-  for (unsigned i=0; i<N; ++i) {
-    HandlerInfo &hi = handlerInfo[i];
+  for (auto &hi : handlerInfo) {
     Function *f = executor.kmodule->module->getFunction(hi.name);
-    
+
     if (f && (!hi.doNotOverride || f->isDeclaration()))
       handlers[f] = std::make_pair(hi.handler, hi.hasReturnValue);
   }
diff --git a/lib/Core/SpecialFunctionHandler.h b/lib/Core/SpecialFunctionHandler.h
index 230d3929..3fdbf8f8 100644
--- a/lib/Core/SpecialFunctionHandler.h
+++ b/lib/Core/SpecialFunctionHandler.h
@@ -12,7 +12,6 @@
 
 #include "klee/Config/config.h"
 
-#include <iterator>
 #include <map>
 #include <vector>
 #include <string>
@@ -48,36 +47,6 @@ namespace klee {
       bool doNotOverride; /// Intrinsic should not be used if already defined
     };
 
-    // const_iterator to iterate over stored HandlerInfo
-    // FIXME: Implement >, >=, <=, < operators
-    class const_iterator {
-      using iterator_category = std::random_access_iterator_tag;
-      using value_type = HandlerInfo;
-      using difference_type = ptrdiff_t;
-      using pointer = void;
-      using reference = void;
-
-    private:
-      value_type *base;
-      int index;
-
-    public:
-      const_iterator(value_type* hi) : base(hi), index(0) {};
-      const_iterator& operator++();  // pre-fix
-      const_iterator operator++(int); // post-fix
-      const value_type& operator*() { return base[index];}
-      const value_type* operator->() { return &(base[index]);}
-      const value_type& operator[](int i) { return base[i];}
-      bool operator==(const_iterator& rhs) { return (rhs.base + rhs.index) == (this->base + this->index);}
-      bool operator!=(const_iterator& rhs) { return !(*this == rhs);}
-    };
-
-    static const_iterator begin();
-    static const_iterator end();
-    static int size();
-
-
-
   public:
     SpecialFunctionHandler(Executor &_executor);