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 +++++++------------------------------ 1 file changed, 8 insertions(+), 38 deletions(-) (limited to 'lib/Core/SpecialFunctionHandler.cpp') 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); } -- cgit 1.4.1