Rename BugHuntingException to ExprEngineException
This commit is contained in:
parent
d4bd3016da
commit
0e736e0c29
|
@ -149,8 +149,8 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
struct BugHuntingException {
|
struct ExprEngineException {
|
||||||
BugHuntingException(const Token *tok, const std::string &what) : tok(tok), what(what) {}
|
ExprEngineException(const Token *tok, const std::string &what) : tok(tok), what(what) {}
|
||||||
const Token *tok;
|
const Token *tok;
|
||||||
const std::string what;
|
const std::string what;
|
||||||
};
|
};
|
||||||
|
@ -1088,12 +1088,12 @@ struct ExprData {
|
||||||
return op1 * z3::pw(context.int_val(2), op2);
|
return op1 * z3::pw(context.int_val(2), op2);
|
||||||
if (b->binop == ">>")
|
if (b->binop == ">>")
|
||||||
return op1 / z3::pw(context.int_val(2), op2);
|
return op1 / z3::pw(context.int_val(2), op2);
|
||||||
throw BugHuntingException(nullptr, "Internal error: Unhandled operator " + b->binop);
|
throw ExprEngineException(nullptr, "Internal error: Unhandled operator " + b->binop);
|
||||||
}
|
}
|
||||||
|
|
||||||
z3::expr getExpr(ExprEngine::ValuePtr v) {
|
z3::expr getExpr(ExprEngine::ValuePtr v) {
|
||||||
if (!v)
|
if (!v)
|
||||||
throw BugHuntingException(nullptr, "Can not solve expressions, operand value is null");
|
throw ExprEngineException(nullptr, "Can not solve expressions, operand value is null");
|
||||||
if (auto intRange = std::dynamic_pointer_cast<ExprEngine::IntRange>(v)) {
|
if (auto intRange = std::dynamic_pointer_cast<ExprEngine::IntRange>(v)) {
|
||||||
if (intRange->name[0] != '$')
|
if (intRange->name[0] != '$')
|
||||||
#if Z3_VERSION_INT >= GET_VERSION_INT(4,7,1)
|
#if Z3_VERSION_INT >= GET_VERSION_INT(4,7,1)
|
||||||
|
@ -1120,7 +1120,7 @@ struct ExprData {
|
||||||
|
|
||||||
if (auto c = std::dynamic_pointer_cast<ExprEngine::ConditionalValue>(v)) {
|
if (auto c = std::dynamic_pointer_cast<ExprEngine::ConditionalValue>(v)) {
|
||||||
if (c->values.empty())
|
if (c->values.empty())
|
||||||
throw BugHuntingException(nullptr, "ConditionalValue is empty");
|
throw ExprEngineException(nullptr, "ConditionalValue is empty");
|
||||||
|
|
||||||
if (c->values.size() == 1)
|
if (c->values.size() == 1)
|
||||||
return getExpr(c->values[0].second);
|
return getExpr(c->values[0].second);
|
||||||
|
@ -1138,7 +1138,7 @@ struct ExprData {
|
||||||
if (v->type == ExprEngine::ValueType::UninitValue)
|
if (v->type == ExprEngine::ValueType::UninitValue)
|
||||||
return context.int_val(0);
|
return context.int_val(0);
|
||||||
|
|
||||||
throw BugHuntingException(nullptr, "Internal error: Unhandled value type");
|
throw ExprEngineException(nullptr, "Internal error: Unhandled value type");
|
||||||
}
|
}
|
||||||
|
|
||||||
z3::expr getConstraintExpr(ExprEngine::ValuePtr v) {
|
z3::expr getConstraintExpr(ExprEngine::ValuePtr v) {
|
||||||
|
@ -1515,8 +1515,8 @@ static void call(const std::vector<ExprEngine::Callback> &callbacks, const Token
|
||||||
for (ExprEngine::Callback f : callbacks) {
|
for (ExprEngine::Callback f : callbacks) {
|
||||||
try {
|
try {
|
||||||
f(tok, *value, dataBase);
|
f(tok, *value, dataBase);
|
||||||
} catch (const BugHuntingException &e) {
|
} catch (const ExprEngineException &e) {
|
||||||
throw BugHuntingException(tok, e.what);
|
throw ExprEngineException(tok, e.what);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1689,7 +1689,7 @@ static ExprEngine::ValuePtr executeAssign(const Token *tok, Data &data)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!rhsValue)
|
if (!rhsValue)
|
||||||
throw BugHuntingException(tok, "Expression '" + tok->expressionString() + "'; Failed to evaluate RHS");
|
throw ExprEngineException(tok, "Expression '" + tok->expressionString() + "'; Failed to evaluate RHS");
|
||||||
|
|
||||||
ExprEngine::ValuePtr assignValue;
|
ExprEngine::ValuePtr assignValue;
|
||||||
if (tok->str() == "=")
|
if (tok->str() == "=")
|
||||||
|
@ -1775,7 +1775,7 @@ static void checkContract(Data &data, const Token *tok, const Function *function
|
||||||
}
|
}
|
||||||
} catch (const z3::exception &exception) {
|
} catch (const z3::exception &exception) {
|
||||||
std::cerr << "z3: " << exception << std::endl;
|
std::cerr << "z3: " << exception << std::endl;
|
||||||
} catch (const BugHuntingException &e) {
|
} catch (const ExprEngineException &e) {
|
||||||
const char id[] = "internalErrorInExprEngine";
|
const char id[] = "internalErrorInExprEngine";
|
||||||
const auto contractIt = data.settings->functionContracts.find(function->fullName());
|
const auto contractIt = data.settings->functionContracts.find(function->fullName());
|
||||||
const std::string functionName = contractIt->first;
|
const std::string functionName = contractIt->first;
|
||||||
|
@ -1878,7 +1878,7 @@ static ExprEngine::ValuePtr executeFunctionCall(const Token *tok, Data &data)
|
||||||
auto v = data.getValue(ref.second, nullptr, nullptr);
|
auto v = data.getValue(ref.second, nullptr, nullptr);
|
||||||
assignExprValue(ref.first, v, data);
|
assignExprValue(ref.first, v, data);
|
||||||
}
|
}
|
||||||
} catch (BugHuntingException &e) {
|
} catch (ExprEngineException &e) {
|
||||||
data.errorPath.pop_back();
|
data.errorPath.pop_back();
|
||||||
e.tok = tok;
|
e.tok = tok;
|
||||||
throw e;
|
throw e;
|
||||||
|
@ -2239,7 +2239,7 @@ static std::string execute(const Token *start, const Token *end, Data &data)
|
||||||
|
|
||||||
if (Token::simpleMatch(tok, "try"))
|
if (Token::simpleMatch(tok, "try"))
|
||||||
// TODO this is a bailout
|
// TODO this is a bailout
|
||||||
throw BugHuntingException(tok, "Unhandled:" + tok->str());
|
throw ExprEngineException(tok, "Unhandled:" + tok->str());
|
||||||
|
|
||||||
// Variable declaration..
|
// Variable declaration..
|
||||||
if (tok->variable() && tok->variable()->nameToken() == tok) {
|
if (tok->variable() && tok->variable()->nameToken() == tok) {
|
||||||
|
@ -2286,7 +2286,7 @@ static std::string execute(const Token *start, const Token *end, Data &data)
|
||||||
auto exec = [&](const Token *tok1, const Token *tok2, Data& data) {
|
auto exec = [&](const Token *tok1, const Token *tok2, Data& data) {
|
||||||
try {
|
try {
|
||||||
execute(tok1, tok2, data);
|
execute(tok1, tok2, data);
|
||||||
} catch (BugHuntingException &e) {
|
} catch (ExprEngineException &e) {
|
||||||
if (!exceptionToken || (e.tok && precedes(e.tok, exceptionToken))) {
|
if (!exceptionToken || (e.tok && precedes(e.tok, exceptionToken))) {
|
||||||
exceptionToken = e.tok;
|
exceptionToken = e.tok;
|
||||||
exceptionMessage = e.what;
|
exceptionMessage = e.what;
|
||||||
|
@ -2304,7 +2304,7 @@ static std::string execute(const Token *start, const Token *end, Data &data)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (exceptionToken)
|
if (exceptionToken)
|
||||||
throw BugHuntingException(exceptionToken, exceptionMessage);
|
throw ExprEngineException(exceptionToken, exceptionMessage);
|
||||||
|
|
||||||
return thenData.str() + elseData.str();
|
return thenData.str() + elseData.str();
|
||||||
}
|
}
|
||||||
|
@ -2322,7 +2322,7 @@ static std::string execute(const Token *start, const Token *end, Data &data)
|
||||||
try {
|
try {
|
||||||
execute(tok1, tok2, data);
|
execute(tok1, tok2, data);
|
||||||
ret << data.str();
|
ret << data.str();
|
||||||
} catch (BugHuntingException &e) {
|
} catch (ExprEngineException &e) {
|
||||||
if (!exceptionToken || (e.tok && precedes(e.tok, exceptionToken))) {
|
if (!exceptionToken || (e.tok && precedes(e.tok, exceptionToken))) {
|
||||||
exceptionToken = e.tok;
|
exceptionToken = e.tok;
|
||||||
exceptionMessage = e.what;
|
exceptionMessage = e.what;
|
||||||
|
@ -2353,7 +2353,7 @@ static std::string execute(const Token *start, const Token *end, Data &data)
|
||||||
}
|
}
|
||||||
exec(defaultStart ? defaultStart : bodyEnd, end, defaultData);
|
exec(defaultStart ? defaultStart : bodyEnd, end, defaultData);
|
||||||
if (exceptionToken)
|
if (exceptionToken)
|
||||||
throw BugHuntingException(exceptionToken, exceptionMessage);
|
throw ExprEngineException(exceptionToken, exceptionMessage);
|
||||||
return ret.str();
|
return ret.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2381,14 +2381,14 @@ static std::string execute(const Token *start, const Token *end, Data &data)
|
||||||
while (Token::simpleMatch(lhs, "["))
|
while (Token::simpleMatch(lhs, "["))
|
||||||
lhs = lhs->astOperand1();
|
lhs = lhs->astOperand1();
|
||||||
if (!lhs)
|
if (!lhs)
|
||||||
throw BugHuntingException(tok2, "Unhandled assignment in loop");
|
throw ExprEngineException(tok2, "Unhandled assignment in loop");
|
||||||
if (Token::Match(lhs, ". %name% =|[") && lhs->astOperand1() && lhs->astOperand1()->valueType()) {
|
if (Token::Match(lhs, ". %name% =|[") && lhs->astOperand1() && lhs->astOperand1()->valueType()) {
|
||||||
const Token *structToken = lhs->astOperand1();
|
const Token *structToken = lhs->astOperand1();
|
||||||
if (!structToken->valueType() || !structToken->varId())
|
if (!structToken->valueType() || !structToken->varId())
|
||||||
throw BugHuntingException(tok2, "Unhandled assignment in loop");
|
throw ExprEngineException(tok2, "Unhandled assignment in loop");
|
||||||
const Scope *structScope = structToken->valueType()->typeScope;
|
const Scope *structScope = structToken->valueType()->typeScope;
|
||||||
if (!structScope)
|
if (!structScope)
|
||||||
throw BugHuntingException(tok2, "Unhandled assignment in loop");
|
throw ExprEngineException(tok2, "Unhandled assignment in loop");
|
||||||
const std::string &memberName = tok2->previous()->str();
|
const std::string &memberName = tok2->previous()->str();
|
||||||
ExprEngine::ValuePtr memberValue;
|
ExprEngine::ValuePtr memberValue;
|
||||||
for (const Variable &member : structScope->varlist) {
|
for (const Variable &member : structScope->varlist) {
|
||||||
|
@ -2398,14 +2398,14 @@ static std::string execute(const Token *start, const Token *end, Data &data)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!memberValue)
|
if (!memberValue)
|
||||||
throw BugHuntingException(tok2, "Unhandled assignment in loop");
|
throw ExprEngineException(tok2, "Unhandled assignment in loop");
|
||||||
|
|
||||||
ExprEngine::ValuePtr structVal1 = data.getValue(structToken->varId(), structToken->valueType(), structToken);
|
ExprEngine::ValuePtr structVal1 = data.getValue(structToken->varId(), structToken->valueType(), structToken);
|
||||||
if (!structVal1)
|
if (!structVal1)
|
||||||
structVal1 = createVariableValue(*structToken->variable(), data);
|
structVal1 = createVariableValue(*structToken->variable(), data);
|
||||||
auto structVal = std::dynamic_pointer_cast<ExprEngine::StructValue>(structVal1);
|
auto structVal = std::dynamic_pointer_cast<ExprEngine::StructValue>(structVal1);
|
||||||
if (!structVal)
|
if (!structVal)
|
||||||
throw BugHuntingException(tok2, "Unhandled assignment in loop");
|
throw ExprEngineException(tok2, "Unhandled assignment in loop");
|
||||||
|
|
||||||
data.assignStructMember(tok2, &*structVal, memberName, memberValue);
|
data.assignStructMember(tok2, &*structVal, memberName, memberValue);
|
||||||
continue;
|
continue;
|
||||||
|
@ -2421,7 +2421,7 @@ static std::string execute(const Token *start, const Token *end, Data &data)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!lhs->variable())
|
if (!lhs->variable())
|
||||||
throw BugHuntingException(tok2, "Unhandled assignment in loop");
|
throw ExprEngineException(tok2, "Unhandled assignment in loop");
|
||||||
// give variable "any" value
|
// give variable "any" value
|
||||||
int varid = lhs->varId();
|
int varid = lhs->varId();
|
||||||
if (changedVariables.find(varid) != changedVariables.end())
|
if (changedVariables.find(varid) != changedVariables.end())
|
||||||
|
@ -2466,7 +2466,7 @@ void ExprEngine::executeAllFunctions(ErrorLogger *errorLogger, const Tokenizer *
|
||||||
for (const Scope *functionScope : symbolDatabase->functionScopes) {
|
for (const Scope *functionScope : symbolDatabase->functionScopes) {
|
||||||
try {
|
try {
|
||||||
executeFunction(functionScope, errorLogger, tokenizer, settings, callbacks, report);
|
executeFunction(functionScope, errorLogger, tokenizer, settings, callbacks, report);
|
||||||
} catch (const BugHuntingException &e) {
|
} catch (const ExprEngineException &e) {
|
||||||
// FIXME.. there should not be exceptions
|
// FIXME.. there should not be exceptions
|
||||||
std::string functionName = functionScope->function->name();
|
std::string functionName = functionScope->function->name();
|
||||||
std::cout << "Verify: Aborted analysis of function '" << functionName << "':" << e.tok->linenr() << ": " << e.what << std::endl;
|
std::cout << "Verify: Aborted analysis of function '" << functionName << "':" << e.tok->linenr() << ": " << e.what << std::endl;
|
||||||
|
@ -2580,9 +2580,9 @@ void ExprEngine::executeFunction(const Scope *functionScope, ErrorLogger *errorL
|
||||||
|
|
||||||
try {
|
try {
|
||||||
execute(functionScope->bodyStart, functionScope->bodyEnd, data);
|
execute(functionScope->bodyStart, functionScope->bodyEnd, data);
|
||||||
} catch (BugHuntingException &e) {
|
} catch (ExprEngineException &e) {
|
||||||
if (settings->debugBugHunting)
|
if (settings->debugBugHunting)
|
||||||
report << "BugHuntingException tok.line:" << e.tok->linenr() << " what:" << e.what << "\n";
|
report << "ExprEngineException tok.line:" << e.tok->linenr() << " what:" << e.what << "\n";
|
||||||
trackExecution.setAbortLine(e.tok->linenr());
|
trackExecution.setAbortLine(e.tok->linenr());
|
||||||
auto bailoutValue = std::make_shared<BailoutValue>();
|
auto bailoutValue = std::make_shared<BailoutValue>();
|
||||||
for (const Token *tok = e.tok; tok != functionScope->bodyEnd; tok = tok->next()) {
|
for (const Token *tok = e.tok; tok != functionScope->bodyEnd; tok = tok->next()) {
|
||||||
|
|
Loading…
Reference in New Issue