From dab1c0fa376771be1c3cdd5b8d564484755907dd Mon Sep 17 00:00:00 2001 From: Julian Büning Date: Sun, 11 Jun 2023 15:45:26 +0200 Subject: SpecialFunctionHandler: use std::array for handlerInfo --- lib/Core/SpecialFunctionHandler.cpp | 46 +++++++------------------------------ lib/Core/SpecialFunctionHandler.h | 31 ------------------------- 2 files changed, 8 insertions(+), 69 deletions(-) (limited to 'lib') 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 #include #include @@ -69,11 +70,11 @@ cl::opt // 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 &preservedFunctions) { - unsigned N = size(); - - for (unsigned i=0; imodule->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; imodule->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 #include #include #include @@ -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); -- cgit 1.4.1