Fixed testrunner
This commit is contained in:
parent
a0770f05e1
commit
f34ff9325a
|
@ -440,6 +440,7 @@ bool extractForLoopValues(const Token *forToken,
|
||||||
nonneg int * const varid,
|
nonneg int * const varid,
|
||||||
bool * const knownInitValue,
|
bool * const knownInitValue,
|
||||||
MathLib::bigint * const initValue,
|
MathLib::bigint * const initValue,
|
||||||
|
bool * const partialCond,
|
||||||
MathLib::bigint * const stepValue,
|
MathLib::bigint * const stepValue,
|
||||||
MathLib::bigint * const lastValue)
|
MathLib::bigint * const lastValue)
|
||||||
{
|
{
|
||||||
|
@ -453,6 +454,16 @@ bool extractForLoopValues(const Token *forToken,
|
||||||
*varid = initExpr->astOperand1()->varId();
|
*varid = initExpr->astOperand1()->varId();
|
||||||
*knownInitValue = initExpr->astOperand2()->hasKnownIntValue();
|
*knownInitValue = initExpr->astOperand2()->hasKnownIntValue();
|
||||||
*initValue = (*knownInitValue) ? initExpr->astOperand2()->getKnownIntValue() : 0;
|
*initValue = (*knownInitValue) ? initExpr->astOperand2()->getKnownIntValue() : 0;
|
||||||
|
*partialCond = Token::Match(condExpr, "%oror%|&&");
|
||||||
|
visitAstNodes(condExpr, [varid, &condExpr](const Token *tok) {
|
||||||
|
if (Token::Match(tok, "%oror%|&&"))
|
||||||
|
return ChildrenToVisit::op1_and_op2;
|
||||||
|
if (Token::Match(tok, "<|<=") && tok->isBinaryOp() && tok->astOperand1()->varId() == *varid && tok->astOperand2()->hasKnownIntValue()) {
|
||||||
|
if (Token::Match(condExpr, "%oror%|&&") || tok->astOperand2()->getKnownIntValue() < condExpr->astOperand2()->getKnownIntValue())
|
||||||
|
condExpr = tok;
|
||||||
|
}
|
||||||
|
return ChildrenToVisit::none;
|
||||||
|
});
|
||||||
if (!Token::Match(condExpr, "<|<=") || !condExpr->isBinaryOp() || condExpr->astOperand1()->varId() != *varid || !condExpr->astOperand2()->hasKnownIntValue())
|
if (!Token::Match(condExpr, "<|<=") || !condExpr->isBinaryOp() || condExpr->astOperand1()->varId() != *varid || !condExpr->astOperand2()->hasKnownIntValue())
|
||||||
return false;
|
return false;
|
||||||
if (!incExpr || !incExpr->isUnaryOp("++") || incExpr->astOperand1()->varId() != *varid)
|
if (!incExpr || !incExpr->isUnaryOp("++") || incExpr->astOperand1()->varId() != *varid)
|
||||||
|
|
|
@ -115,6 +115,7 @@ bool extractForLoopValues(const Token *forToken,
|
||||||
nonneg int * const varid,
|
nonneg int * const varid,
|
||||||
bool * const knownInitValue,
|
bool * const knownInitValue,
|
||||||
long long * const initValue,
|
long long * const initValue,
|
||||||
|
bool * const partialCond,
|
||||||
long long * const stepValue,
|
long long * const stepValue,
|
||||||
long long * const lastValue);
|
long long * const lastValue);
|
||||||
|
|
||||||
|
|
|
@ -2371,9 +2371,9 @@ static std::string execute(const Token *start, const Token *end, Data &data)
|
||||||
|
|
||||||
if (Token::simpleMatch(tok, "for (")) {
|
if (Token::simpleMatch(tok, "for (")) {
|
||||||
nonneg int varid;
|
nonneg int varid;
|
||||||
bool hasKnownInitValue;
|
bool hasKnownInitValue, partialCond;
|
||||||
MathLib::bigint initValue, stepValue, lastValue;
|
MathLib::bigint initValue, stepValue, lastValue;
|
||||||
if (extractForLoopValues(tok, &varid, &hasKnownInitValue, &initValue, &stepValue, &lastValue) && hasKnownInitValue) {
|
if (extractForLoopValues(tok, &varid, &hasKnownInitValue, &initValue, &partialCond, &stepValue, &lastValue) && hasKnownInitValue && !partialCond) {
|
||||||
auto loopValues = std::make_shared<ExprEngine::IntRange>(data.getNewSymbolName(), initValue, lastValue);
|
auto loopValues = std::make_shared<ExprEngine::IntRange>(data.getNewSymbolName(), initValue, lastValue);
|
||||||
data.assignValue(tok, varid, loopValues);
|
data.assignValue(tok, varid, loopValues);
|
||||||
tok = tok->linkAt(1);
|
tok = tok->linkAt(1);
|
||||||
|
|
|
@ -4626,10 +4626,10 @@ static void valueFlowForLoop(TokenList *tokenlist, SymbolDatabase* symboldatabas
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
nonneg int varid;
|
nonneg int varid;
|
||||||
bool knownInitValue;
|
bool knownInitValue, partialCond;
|
||||||
MathLib::bigint initValue, stepValue, lastValue;
|
MathLib::bigint initValue, stepValue, lastValue;
|
||||||
|
|
||||||
if (extractForLoopValues(tok, &varid, &knownInitValue, &initValue, &stepValue, &lastValue)) {
|
if (extractForLoopValues(tok, &varid, &knownInitValue, &initValue, &partialCond, &stepValue, &lastValue)) {
|
||||||
const bool executeBody = !knownInitValue || initValue <= lastValue;
|
const bool executeBody = !knownInitValue || initValue <= lastValue;
|
||||||
if (executeBody) {
|
if (executeBody) {
|
||||||
valueFlowForLoopSimplify(bodyStart, varid, false, initValue, tokenlist, errorLogger, settings);
|
valueFlowForLoopSimplify(bodyStart, varid, false, initValue, tokenlist, errorLogger, settings);
|
||||||
|
|
Loading…
Reference in New Issue