From 713c1a3744aa8c0bfadf85a76377dd2c7dd63519 Mon Sep 17 00:00:00 2001 From: Martin Nowack Date: Wed, 17 Oct 2018 22:39:06 +0100 Subject: optimizeExpr: return the result as return value instead as function argument simplifies code a lot. --- lib/Core/Executor.cpp | 90 +++++++++------------------------------------------ 1 file changed, 15 insertions(+), 75 deletions(-) (limited to 'lib/Core') diff --git a/lib/Core/Executor.cpp b/lib/Core/Executor.cpp index f0335812..35178106 100644 --- a/lib/Core/Executor.cpp +++ b/lib/Core/Executor.cpp @@ -1087,11 +1087,7 @@ ref Executor::toUnique(const ExecutionState &state, bool isTrue = false; if ((OptimizeArray == ALL || OptimizeArray == VALUE) && !isa(e)) { - ref res; - optimizer.optimizeExpr(e, res, true); - if (res.get()) { - e = res; - } + e = optimizer.optimizeExpr(e, true); } solver->setTimeout(coreSolverTimeout); if (solver->getValue(state, e, value)) { @@ -1099,11 +1095,7 @@ ref Executor::toUnique(const ExecutionState &state, if ((OptimizeArray == ALL || OptimizeArray == VALUE || OptimizeArray == INDEX) && !isa(cond)) { - ref res; - optimizer.optimizeExpr(cond, res, false); - if (res.get()) { - cond = res; - } + cond = optimizer.optimizeExpr(cond, false); } if (solver->mustBeTrue(state, cond, isTrue) && isTrue) result = value; @@ -1156,11 +1148,7 @@ void Executor::executeGetValue(ExecutionState &state, ref value; if ((OptimizeArray == ALL || OptimizeArray == VALUE) && !isa(e)) { - ref result; - optimizer.optimizeExpr(e, result, true); - if (result.get()) { - e = result; - } + e = optimizer.optimizeExpr(e, true); } bool success = solver->getValue(state, e, value); assert(success && "FIXME: Unhandled solver failure"); @@ -1173,11 +1161,7 @@ void Executor::executeGetValue(ExecutionState &state, ref cond = siit->assignment.evaluate(e); if ((OptimizeArray == ALL || OptimizeArray == VALUE) && !isa(cond)) { - ref result; - optimizer.optimizeExpr(cond, result, true); - if (result.get()) { - cond = result; - } + cond = optimizer.optimizeExpr(cond, true); } ref value; bool success = solver->getValue(state, cond, value); @@ -1611,11 +1595,7 @@ void Executor::executeInstruction(ExecutionState &state, KInstruction *ki) { if ((OptimizeArray == ALL || OptimizeArray == VALUE || OptimizeArray == INDEX) && !isa(cond)) { - ref result; - optimizer.optimizeExpr(cond, result, false); - if (result.get()) { - cond = result; - } + cond = optimizer.optimizeExpr(cond, false); } Executor::StatePair branches = fork(state, cond, false); @@ -1764,11 +1744,7 @@ void Executor::executeInstruction(ExecutionState &state, KInstruction *ki) { if ((OptimizeArray == ALL || OptimizeArray == VALUE || OptimizeArray == INDEX) && !isa(match)) { - ref result; - optimizer.optimizeExpr(match, result, false); - if (result.get()) { - match = result; - } + match = optimizer.optimizeExpr(match, false); } bool success = solver->mayBeTrue(state, match, result); assert(success && "FIXME: Unhandled solver failure"); @@ -1799,11 +1775,7 @@ void Executor::executeInstruction(ExecutionState &state, KInstruction *ki) { if ((OptimizeArray == ALL || OptimizeArray == VALUE || OptimizeArray == INDEX) && !isa(defaultValue)) { - ref result; - optimizer.optimizeExpr(defaultValue, result, false); - if (result.get()) { - defaultValue = result; - } + defaultValue = optimizer.optimizeExpr(defaultValue, false); } bool res; bool success = solver->mayBeTrue(state, defaultValue, res); @@ -1922,11 +1894,7 @@ void Executor::executeInstruction(ExecutionState &state, KInstruction *ki) { do { if ((OptimizeArray == ALL || OptimizeArray == VALUE) && !isa(v)) { - ref result; - optimizer.optimizeExpr(v, result, true); - if (result.get()) { - v = result; - } + v = optimizer.optimizeExpr(v, true); } ref value; bool success = solver->getValue(*free, v, value); @@ -3163,11 +3131,7 @@ void Executor::callExternalFunction(ExecutionState &state, if (AllowExternalSymCalls) { // don't bother checking uniqueness if ((OptimizeArray == ALL || OptimizeArray == VALUE) && !isa(*ai)) { - ref result; - optimizer.optimizeExpr(*ai, result, true); - if (result.get()) { - *ai = result; - } + *ai = optimizer.optimizeExpr(*ai, true); } ref ce; bool success = solver->getValue(state, *ai, ce); @@ -3357,11 +3321,7 @@ void Executor::executeAlloc(ExecutionState &state, if ((OptimizeArray == ALL || OptimizeArray == VALUE) && !isa(size)) { - ref result; - optimizer.optimizeExpr(size, result, true); - if (result.get()) { - size = result; - } + size = optimizer.optimizeExpr(size, true); } ref example; @@ -3436,11 +3396,7 @@ void Executor::executeFree(ExecutionState &state, KInstruction *target) { if ((OptimizeArray == ALL || OptimizeArray == VALUE) && !isa(address)) { - ref result; - optimizer.optimizeExpr(address, result, true); - if (result.get()) { - address = result; - } + address = optimizer.optimizeExpr(address, true); } StatePair zeroPointer = fork(state, Expr::createIsZero(address), true); if (zeroPointer.first) { @@ -3475,11 +3431,7 @@ void Executor::resolveExact(ExecutionState &state, const std::string &name) { if ((OptimizeArray == ALL || OptimizeArray == VALUE) && !isa(p)) { - ref result; - optimizer.optimizeExpr(p, result, true); - if (result.get()) { - p = result; - } + p = optimizer.optimizeExpr(p, true); } // XXX we may want to be capping this? ResolutionList rl; @@ -3523,11 +3475,7 @@ void Executor::executeMemoryOperation(ExecutionState &state, } if ((OptimizeArray == VALUE) && !isa(address)) { - ref result; - optimizer.optimizeExpr(address, result, true); - if (result.get()) { - address = result; - } + address = optimizer.optimizeExpr(address, true); } // fast path: single in-bounds resolution @@ -3551,11 +3499,7 @@ void Executor::executeMemoryOperation(ExecutionState &state, ref check = mo->getBoundsCheckOffset(offset, bytes); if ((OptimizeArray == ALL || OptimizeArray == VALUE) && !isa(check)) { - ref result; - optimizer.optimizeExpr(check, result, true); - if (result.get()) { - check = result; - } + check = optimizer.optimizeExpr(check, true); } bool inBounds; @@ -3596,11 +3540,7 @@ void Executor::executeMemoryOperation(ExecutionState &state, if ((OptimizeArray == ALL || OptimizeArray == VALUE) && !isa(address)) { - ref result; - optimizer.optimizeExpr(address, result, true); - if (result.get()) { - address = result; - } + address = optimizer.optimizeExpr(address, true); } ResolutionList rl; solver->setTimeout(coreSolverTimeout); -- cgit 1.4.1