From cb5e898561f9b8769d8838bc1bdca17a6f4f5d20 Mon Sep 17 00:00:00 2001 From: Cristian Cadar Date: Thu, 30 Nov 2023 20:35:55 +0000 Subject: Modify getValueFromSeeds() to include more functionality and simplify its callers --- lib/Core/Executor.cpp | 30 ++++++++++++------------------ 1 file changed, 12 insertions(+), 18 deletions(-) (limited to 'lib/Core/Executor.cpp') diff --git a/lib/Core/Executor.cpp b/lib/Core/Executor.cpp index 73f994ce..49df9790 100644 --- a/lib/Core/Executor.cpp +++ b/lib/Core/Executor.cpp @@ -1321,11 +1321,8 @@ Executor::toConstant(ExecutionState &state, if (ConstantExpr *CE = dyn_cast(e)) return CE; - ref value; - if (auto found = seedMap.find(&state); found != seedMap.end()) - value = getValueFromSeeds(found->second, e); /* If no seed evaluation results in a constant, call the solver */ - ref cvalue = llvm::dyn_cast_or_null(value); + ref cvalue = getValueFromSeeds(state, e); if (!cvalue) { [[maybe_unused]] bool success = solver->getValue(state.constraints, e, cvalue, state.queryMetaData); @@ -1348,9 +1345,13 @@ Executor::toConstant(ExecutionState &state, return cvalue; } -ref -Executor::getValueFromSeeds(std::vector &seeds, ref e) { - assert(!seeds.empty()); +ref Executor::getValueFromSeeds(ExecutionState &state, + ref e) { + auto found = seedMap.find(&state); + if (found == seedMap.end()) + return nullptr; + + auto seeds = found->second; for (auto const &seed : seeds) { auto value = seed.assignment.evaluate(e); if (isa(value)) @@ -3958,12 +3959,9 @@ void Executor::callExternalFunction(ExecutionState &state, ae = arguments.end(); ai!=ae; ++ai) { if (ExternalCalls == ExternalCallPolicy::All) { // don't bother checking uniqueness *ai = optimizer.optimizeExpr(*ai, true); - ref cvalue; - ref value = nullptr; - if (auto found = seedMap.find(&state); found != seedMap.end()) - value = getValueFromSeeds(found->second, *ai); + ref cvalue = getValueFromSeeds(state, *ai); /* If no seed evaluation results in a constant, call the solver */ - if (!value || !(cvalue = dyn_cast(value))) { + if (!cvalue) { [[maybe_unused]] bool success = solver->getValue( state.constraints, *ai, cvalue, state.queryMetaData); assert(success && "FIXME: Unhandled solver failure"); @@ -4196,13 +4194,9 @@ void Executor::executeAlloc(ExecutionState &state, size = optimizer.optimizeExpr(size, true); - ref example; // Check if in seed mode, then try to replicate size from a seed - ref value = nullptr; - if (auto found = seedMap.find(&state); found != seedMap.end()) - value = getValueFromSeeds(found->second, size); - /* If no seed evaluation results in a constant, call the solver */ - if (!value || !(example = dyn_cast(value))) { + ref example = getValueFromSeeds(state, size); + if (!example) { bool success = solver->getValue(state.constraints, size, example, state.queryMetaData); assert(success && "FIXME: Unhandled solver failure"); -- cgit 1.4.1