Rename VerifyException to BugHuntingException
This commit is contained in:
parent
86e64f6224
commit
b36c85d8fd
|
@ -150,8 +150,8 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
struct VerifyException {
|
struct BugHuntingException {
|
||||||
VerifyException(const Token *tok, const std::string &what) : tok(tok), what(what) {}
|
BugHuntingException(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;
|
||||||
};
|
};
|
||||||
|
@ -834,12 +834,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 VerifyException(nullptr, "Internal error: Unhandled operator " + b->binop);
|
throw BugHuntingException(nullptr, "Internal error: Unhandled operator " + b->binop);
|
||||||
}
|
}
|
||||||
|
|
||||||
z3::expr getExpr(ExprEngine::ValuePtr v) {
|
z3::expr getExpr(ExprEngine::ValuePtr v) {
|
||||||
if (!v)
|
if (!v)
|
||||||
throw VerifyException(nullptr, "Can not solve expressions, operand value is null");
|
throw BugHuntingException(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)
|
||||||
|
@ -866,7 +866,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 VerifyException(nullptr, "ConditionalValue is empty");
|
throw BugHuntingException(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);
|
||||||
|
@ -884,7 +884,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 VerifyException(nullptr, "Internal error: Unhandled value type");
|
throw BugHuntingException(nullptr, "Internal error: Unhandled value type");
|
||||||
}
|
}
|
||||||
|
|
||||||
z3::expr getConstraintExpr(ExprEngine::ValuePtr v) {
|
z3::expr getConstraintExpr(ExprEngine::ValuePtr v) {
|
||||||
|
@ -1242,8 +1242,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 VerifyException &e) {
|
} catch (const BugHuntingException &e) {
|
||||||
throw VerifyException(tok, e.what);
|
throw BugHuntingException(tok, e.what);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1314,7 +1314,7 @@ static ExprEngine::ValuePtr executeAssign(const Token *tok, Data &data)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!rhsValue)
|
if (!rhsValue)
|
||||||
throw VerifyException(tok, "Expression '" + tok->expressionString() + "'; Failed to evaluate RHS");
|
throw BugHuntingException(tok, "Expression '" + tok->expressionString() + "'; Failed to evaluate RHS");
|
||||||
|
|
||||||
ExprEngine::ValuePtr assignValue;
|
ExprEngine::ValuePtr assignValue;
|
||||||
if (tok->str() == "=")
|
if (tok->str() == "=")
|
||||||
|
@ -1436,7 +1436,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 VerifyException &e) {
|
} catch (const BugHuntingException &e) {
|
||||||
std::list<const Token*> callstack{tok};
|
std::list<const Token*> callstack{tok};
|
||||||
const char * const id = "internalErrorInExprEngine";
|
const char * const id = "internalErrorInExprEngine";
|
||||||
const auto contractIt = data.settings->functionContracts.find(function->fullName());
|
const auto contractIt = data.settings->functionContracts.find(function->fullName());
|
||||||
|
@ -1813,7 +1813,7 @@ static void execute(const Token *start, const Token *end, Data &data, int recurs
|
||||||
|
|
||||||
if (Token::simpleMatch(tok, "try"))
|
if (Token::simpleMatch(tok, "try"))
|
||||||
// TODO this is a bailout
|
// TODO this is a bailout
|
||||||
throw VerifyException(tok, "Unhandled:" + tok->str());
|
throw BugHuntingException(tok, "Unhandled:" + tok->str());
|
||||||
|
|
||||||
// Variable declaration..
|
// Variable declaration..
|
||||||
if (tok->variable() && tok->variable()->nameToken() == tok) {
|
if (tok->variable() && tok->variable()->nameToken() == tok) {
|
||||||
|
@ -1859,7 +1859,7 @@ static void execute(const Token *start, const Token *end, Data &data, int recurs
|
||||||
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, recursion);
|
execute(tok1, tok2, data, recursion);
|
||||||
} catch (VerifyException &e) {
|
} catch (BugHuntingException &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;
|
||||||
|
@ -1877,7 +1877,7 @@ static void execute(const Token *start, const Token *end, Data &data, int recurs
|
||||||
}
|
}
|
||||||
|
|
||||||
if (exceptionToken)
|
if (exceptionToken)
|
||||||
throw VerifyException(exceptionToken, exceptionMessage);
|
throw BugHuntingException(exceptionToken, exceptionMessage);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1892,7 +1892,7 @@ static void execute(const Token *start, const Token *end, Data &data, int recurs
|
||||||
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, recursion);
|
execute(tok1, tok2, data, recursion);
|
||||||
} catch (VerifyException &e) {
|
} catch (BugHuntingException &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;
|
||||||
|
@ -1917,7 +1917,7 @@ static void execute(const Token *start, const Token *end, Data &data, int recurs
|
||||||
}
|
}
|
||||||
exec(defaultStart ? defaultStart : bodyEnd, end, defaultData);
|
exec(defaultStart ? defaultStart : bodyEnd, end, defaultData);
|
||||||
if (exceptionToken)
|
if (exceptionToken)
|
||||||
throw VerifyException(exceptionToken, exceptionMessage);
|
throw BugHuntingException(exceptionToken, exceptionMessage);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1932,10 +1932,10 @@ static void execute(const Token *start, const Token *end, Data &data, int recurs
|
||||||
if (Token::Match(tok2->astOperand1(), ". %name% =") && tok2->astOperand1()->astOperand1() && tok2->astOperand1()->astOperand1()->valueType()) {
|
if (Token::Match(tok2->astOperand1(), ". %name% =") && tok2->astOperand1()->astOperand1() && tok2->astOperand1()->astOperand1()->valueType()) {
|
||||||
const Token *structToken = tok2->astOperand1()->astOperand1();
|
const Token *structToken = tok2->astOperand1()->astOperand1();
|
||||||
if (!structToken->valueType() || !structToken->varId())
|
if (!structToken->valueType() || !structToken->varId())
|
||||||
throw VerifyException(tok2, "Unhandled assignment in loop");
|
throw BugHuntingException(tok2, "Unhandled assignment in loop");
|
||||||
const Scope *structScope = structToken->valueType()->typeScope;
|
const Scope *structScope = structToken->valueType()->typeScope;
|
||||||
if (!structScope)
|
if (!structScope)
|
||||||
throw VerifyException(tok2, "Unhandled assignment in loop");
|
throw BugHuntingException(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) {
|
||||||
|
@ -1945,14 +1945,14 @@ static void execute(const Token *start, const Token *end, Data &data, int recurs
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!memberValue)
|
if (!memberValue)
|
||||||
throw VerifyException(tok2, "Unhandled assignment in loop");
|
throw BugHuntingException(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 VerifyException(tok2, "Unhandled assignment in loop");
|
throw BugHuntingException(tok2, "Unhandled assignment in loop");
|
||||||
|
|
||||||
data.assignStructMember(tok2, &*structVal, memberName, memberValue);
|
data.assignStructMember(tok2, &*structVal, memberName, memberValue);
|
||||||
continue;
|
continue;
|
||||||
|
@ -1969,9 +1969,9 @@ static void execute(const Token *start, const Token *end, Data &data, int recurs
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!Token::Match(tok2->astOperand1(), "%var%"))
|
if (!Token::Match(tok2->astOperand1(), "%var%"))
|
||||||
throw VerifyException(tok2, "Unhandled assignment in loop");
|
throw BugHuntingException(tok2, "Unhandled assignment in loop");
|
||||||
if (!tok2->astOperand1()->variable())
|
if (!tok2->astOperand1()->variable())
|
||||||
throw VerifyException(tok2, "Unhandled assignment in loop");
|
throw BugHuntingException(tok2, "Unhandled assignment in loop");
|
||||||
// give variable "any" value
|
// give variable "any" value
|
||||||
int varid = tok2->astOperand1()->varId();
|
int varid = tok2->astOperand1()->varId();
|
||||||
if (changedVariables.find(varid) != changedVariables.end())
|
if (changedVariables.find(varid) != changedVariables.end())
|
||||||
|
@ -2007,7 +2007,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 VerifyException &e) {
|
} catch (const BugHuntingException &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;
|
||||||
|
@ -2133,9 +2133,9 @@ void ExprEngine::executeFunction(const Scope *functionScope, ErrorLogger *errorL
|
||||||
|
|
||||||
try {
|
try {
|
||||||
execute(functionScope->bodyStart, functionScope->bodyEnd, data);
|
execute(functionScope->bodyStart, functionScope->bodyEnd, data);
|
||||||
} catch (VerifyException &e) {
|
} catch (BugHuntingException &e) {
|
||||||
if (settings->debugBugHunting)
|
if (settings->debugBugHunting)
|
||||||
report << "VerifyException tok.line:" << e.tok->linenr() << " what:" << e.what << "\n";
|
report << "BugHuntingException 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