From 26f93a74f5d3cbf84ddc392fec792efaa95a8cf4 Mon Sep 17 00:00:00 2001 From: Vladislav Kalugin Date: Fri, 17 Nov 2023 13:39:50 +0300 Subject: [PATCH] Fix after rebase 2 --- lib/Core/Executor.cpp | 53 +++++++++++++++++++++++---------------- lib/Module/Annotation.cpp | 4 +-- 2 files changed, 33 insertions(+), 24 deletions(-) diff --git a/lib/Core/Executor.cpp b/lib/Core/Executor.cpp index b0f55bd7683..8d489af7836 100644 --- a/lib/Core/Executor.cpp +++ b/lib/Core/Executor.cpp @@ -609,8 +609,6 @@ llvm::Module *Executor::setModule( specialFunctionHandler = new SpecialFunctionHandler(*this); specialFunctionHandler->prepare(preservedFunctions); - preservedFunctions.push_back(opts.EntryPoint.c_str()); - // Preserve the free-standing library calls preservedFunctions.push_back("memset"); preservedFunctions.push_back("memcpy"); @@ -618,12 +616,21 @@ llvm::Module *Executor::setModule( preservedFunctions.push_back("memmove"); if (FunctionCallReproduce != "") { - // prevent elimination of the function - auto f = kmodule->module->getFunction(FunctionCallReproduce); - if (f) + preservedFunctions.push_back(FunctionCallReproduce.c_str()); + } + + // prevent elimination of the preservedFunctions functions + for (auto pf : preservedFunctions) { + auto f = kmodule->module->getFunction(pf); + if (f) { f->addFnAttr(Attribute::OptimizeNone); + f->addFnAttr(Attribute::NoInline); + } } + // except the entry point + preservedFunctions.push_back(opts.EntryPoint.c_str()); + kmodule->optimiseAndPrepare(opts, preservedFunctions); kmodule->checkModule(); @@ -2937,18 +2944,22 @@ void Executor::executeInstruction(ExecutionState &state, KInstruction *ki) { } else { ref v = eval(ki, 0, state).value; - if (!isa(v) && interpreterOpts.Mock == MockPolicy::Failed) { - if (ki->inst->getType()->isSized()) { - prepareMockValue(state, "mockExternResult", ki); - } - } else { - ExecutionState *free = &state; - bool hasInvalid = false, first = true; + ExecutionState *free = &state; + bool hasInvalid = false, first = true; + + /* XXX This is wasteful, no need to do a full evaluate since we + have already got a value. But in the end the caches should + handle it for us, albeit with some overhead. */ + do { + if (!isa(v) && + interpreterOpts.Mock == MockPolicy::Failed) { + if (ki->inst->getType()->isSized()) { + prepareMockValue(state, "mockExternResult", ki); + } + } else { + ExecutionState *free = &state; + bool hasInvalid = false, first = true; - /* XXX This is wasteful, no need to do a full evaluate since we - have already got a value. But in the end the caches should - handle it for us, albeit with some overhead. */ - do { v = optimizer.optimizeExpr(v, true); ref value; bool success = solver->getValue(free->constraints.cs(), v, value, @@ -2981,8 +2992,8 @@ void Executor::executeInstruction(ExecutionState &state, KInstruction *ki) { first = false; free = res.second; timers.invoke(); - } while (free && !haltExecution); - } + } + } while (free && !haltExecution); } break; } @@ -6073,10 +6084,10 @@ void Executor::executeMemoryOperation( ref response; solver->setTimeout(coreSolverTimeout); - bool solverResponse = solver->getResponse(state->constraints.cs(), inBounds, - response, state->queryMetaData); + bool success = solver->getResponse(state->constraints.cs(), inBounds, + response, state->queryMetaData); solver->setTimeout(time::Span()); - if (!solverResponse) { + if (!success) { state->pc = state->prevPC; terminateStateOnSolverError(*state, "Query timed out (bounds check)."); return; diff --git a/lib/Module/Annotation.cpp b/lib/Module/Annotation.cpp index 1326a8d9fbe..26b46ed8d43 100644 --- a/lib/Module/Annotation.cpp +++ b/lib/Module/Annotation.cpp @@ -92,9 +92,7 @@ Deref::Deref(const std::string &str) : Unknown(str) {} Kind Deref::getKind() const { return Kind::Deref; } const std::map initNullTypeMap = { - {"maybe", InitNull::Type::MAYBE}, - {"must", InitNull::Type::MUST} -}; + {"maybe", InitNull::Type::MAYBE}, {"must", InitNull::Type::MUST}}; InitNull::InitNull(const std::string &str) : Unknown(str) { if (!rawValue.empty()) {